@pmndrs/vdb 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (570) hide show
  1. package/CHANGELOG.md +727 -0
  2. package/LICENSE +21 -0
  3. package/README.md +496 -2
  4. package/THIRD_PARTY_NOTICES.md +315 -0
  5. package/dist/core/compute/atlas.d.ts +102 -0
  6. package/dist/core/compute/atlas.js +103 -0
  7. package/dist/core/compute/atlas.js.map +1 -0
  8. package/dist/core/compute/index.d.ts +13 -0
  9. package/dist/core/compute/index.js +9 -0
  10. package/dist/core/compute/index.js.map +1 -0
  11. package/dist/core/compute/majorant-build.d.ts +45 -0
  12. package/dist/core/compute/majorant-build.js +193 -0
  13. package/dist/core/compute/majorant-build.js.map +1 -0
  14. package/dist/core/compute/multi-scale.d.ts +155 -0
  15. package/dist/core/compute/multi-scale.js +684 -0
  16. package/dist/core/compute/multi-scale.js.map +1 -0
  17. package/dist/core/compute/pyramid.d.ts +120 -0
  18. package/dist/core/compute/pyramid.js +468 -0
  19. package/dist/core/compute/pyramid.js.map +1 -0
  20. package/dist/core/compute/shared.d.ts +116 -0
  21. package/dist/core/compute/shared.js +211 -0
  22. package/dist/core/compute/shared.js.map +1 -0
  23. package/dist/core/compute/stats.d.ts +78 -0
  24. package/dist/core/compute/stats.js +193 -0
  25. package/dist/core/compute/stats.js.map +1 -0
  26. package/dist/core/compute/value-transform.d.ts +30 -0
  27. package/dist/core/compute/value-transform.js +64 -0
  28. package/dist/core/compute/value-transform.js.map +1 -0
  29. package/dist/core/errors.d.ts +21 -0
  30. package/dist/core/errors.js +17 -0
  31. package/dist/core/errors.js.map +1 -0
  32. package/dist/core/frame/emission.d.ts +85 -0
  33. package/dist/core/frame/emission.js +422 -0
  34. package/dist/core/frame/emission.js.map +1 -0
  35. package/dist/core/frame/environment.d.ts +47 -0
  36. package/dist/core/frame/environment.js +178 -0
  37. package/dist/core/frame/environment.js.map +1 -0
  38. package/dist/core/frame/index.d.ts +39 -0
  39. package/dist/core/frame/index.js +27 -0
  40. package/dist/core/frame/index.js.map +1 -0
  41. package/dist/core/frame/kernels.d.ts +115 -0
  42. package/dist/core/frame/kernels.js +496 -0
  43. package/dist/core/frame/kernels.js.map +1 -0
  44. package/dist/core/frame/limits.d.ts +67 -0
  45. package/dist/core/frame/limits.js +109 -0
  46. package/dist/core/frame/limits.js.map +1 -0
  47. package/dist/core/frame/phase.d.ts +17 -0
  48. package/dist/core/frame/phase.js +53 -0
  49. package/dist/core/frame/phase.js.map +1 -0
  50. package/dist/core/frame/pipelines.d.ts +49 -0
  51. package/dist/core/frame/pipelines.js +147 -0
  52. package/dist/core/frame/pipelines.js.map +1 -0
  53. package/dist/core/frame/renderer.d.ts +122 -0
  54. package/dist/core/frame/renderer.js +1712 -0
  55. package/dist/core/frame/renderer.js.map +1 -0
  56. package/dist/core/frame/resources.d.ts +71 -0
  57. package/dist/core/frame/resources.js +100 -0
  58. package/dist/core/frame/resources.js.map +1 -0
  59. package/dist/core/frame/scattering.d.ts +97 -0
  60. package/dist/core/frame/scattering.js +332 -0
  61. package/dist/core/frame/scattering.js.map +1 -0
  62. package/dist/core/frame/settings.d.ts +243 -0
  63. package/dist/core/frame/settings.js +67 -0
  64. package/dist/core/frame/settings.js.map +1 -0
  65. package/dist/core/frame/shadows.d.ts +55 -0
  66. package/dist/core/frame/shadows.js +460 -0
  67. package/dist/core/frame/shadows.js.map +1 -0
  68. package/dist/core/frame/types.d.ts +415 -0
  69. package/dist/core/frame/types.js +49 -0
  70. package/dist/core/frame/types.js.map +1 -0
  71. package/dist/core/frame/uniforms.d.ts +105 -0
  72. package/dist/core/frame/uniforms.js +276 -0
  73. package/dist/core/frame/uniforms.js.map +1 -0
  74. package/dist/core/frame/wgsl/chunks.d.ts +4 -0
  75. package/dist/core/frame/wgsl/chunks.js +728 -0
  76. package/dist/core/frame/wgsl/chunks.js.map +1 -0
  77. package/dist/core/frame/wgsl/emission.d.ts +82 -0
  78. package/dist/core/frame/wgsl/emission.js +353 -0
  79. package/dist/core/frame/wgsl/emission.js.map +1 -0
  80. package/dist/core/frame/wgsl/environment.d.ts +42 -0
  81. package/dist/core/frame/wgsl/environment.js +711 -0
  82. package/dist/core/frame/wgsl/environment.js.map +1 -0
  83. package/dist/core/frame/wgsl/gather.d.ts +55 -0
  84. package/dist/core/frame/wgsl/gather.js +850 -0
  85. package/dist/core/frame/wgsl/gather.js.map +1 -0
  86. package/dist/core/frame/wgsl/integrate.d.ts +78 -0
  87. package/dist/core/frame/wgsl/integrate.js +213 -0
  88. package/dist/core/frame/wgsl/integrate.js.map +1 -0
  89. package/dist/core/frame/wgsl/lighting.d.ts +103 -0
  90. package/dist/core/frame/wgsl/lighting.js +1636 -0
  91. package/dist/core/frame/wgsl/lighting.js.map +1 -0
  92. package/dist/core/frame/wgsl/occluders.d.ts +20 -0
  93. package/dist/core/frame/wgsl/occluders.js +95 -0
  94. package/dist/core/frame/wgsl/occluders.js.map +1 -0
  95. package/dist/core/frame/wgsl/resolve.d.ts +19 -0
  96. package/dist/core/frame/wgsl/resolve.js +205 -0
  97. package/dist/core/frame/wgsl/resolve.js.map +1 -0
  98. package/dist/core/frame/wgsl/shadows.d.ts +35 -0
  99. package/dist/core/frame/wgsl/shadows.js +328 -0
  100. package/dist/core/frame/wgsl/shadows.js.map +1 -0
  101. package/dist/core/half.d.ts +11 -0
  102. package/dist/core/half.js +22 -0
  103. package/dist/core/half.js.map +1 -0
  104. package/dist/core/index.d.ts +52 -0
  105. package/dist/core/index.js +46 -0
  106. package/dist/core/index.js.map +1 -0
  107. package/dist/core/internal.d.ts +31 -0
  108. package/dist/core/internal.js +32 -0
  109. package/dist/core/internal.js.map +1 -0
  110. package/dist/core/pool/affine.d.ts +34 -0
  111. package/dist/core/pool/affine.js +100 -0
  112. package/dist/core/pool/affine.js.map +1 -0
  113. package/dist/core/pool/allocator.d.ts +32 -0
  114. package/dist/core/pool/allocator.js +81 -0
  115. package/dist/core/pool/allocator.js.map +1 -0
  116. package/dist/core/pool/image-header.d.ts +93 -0
  117. package/dist/core/pool/image-header.js +194 -0
  118. package/dist/core/pool/image-header.js.map +1 -0
  119. package/dist/core/pool/layout.d.ts +198 -0
  120. package/dist/core/pool/layout.js +316 -0
  121. package/dist/core/pool/layout.js.map +1 -0
  122. package/dist/core/pool/limits.d.ts +41 -0
  123. package/dist/core/pool/limits.js +80 -0
  124. package/dist/core/pool/limits.js.map +1 -0
  125. package/dist/core/pool/pool.d.ts +384 -0
  126. package/dist/core/pool/pool.js +1184 -0
  127. package/dist/core/pool/pool.js.map +1 -0
  128. package/dist/core/reference/index.d.ts +6 -0
  129. package/dist/core/reference/index.js +7 -0
  130. package/dist/core/reference/index.js.map +1 -0
  131. package/dist/core/reference/renderer.d.ts +105 -0
  132. package/dist/core/reference/renderer.js +474 -0
  133. package/dist/core/reference/renderer.js.map +1 -0
  134. package/dist/core/reference/wgsl.d.ts +65 -0
  135. package/dist/core/reference/wgsl.js +803 -0
  136. package/dist/core/reference/wgsl.js.map +1 -0
  137. package/dist/core/sequence.d.ts +347 -0
  138. package/dist/core/sequence.js +548 -0
  139. package/dist/core/sequence.js.map +1 -0
  140. package/dist/core/source/brick-cache.d.ts +165 -0
  141. package/dist/core/source/brick-cache.js +627 -0
  142. package/dist/core/source/brick-cache.js.map +1 -0
  143. package/dist/core/source/dense-fill.d.ts +53 -0
  144. package/dist/core/source/dense-fill.js +377 -0
  145. package/dist/core/source/dense-fill.js.map +1 -0
  146. package/dist/core/source/dense.d.ts +50 -0
  147. package/dist/core/source/dense.js +384 -0
  148. package/dist/core/source/dense.js.map +1 -0
  149. package/dist/core/source/sparse-wgsl.d.ts +92 -0
  150. package/dist/core/source/sparse-wgsl.js +481 -0
  151. package/dist/core/source/sparse-wgsl.js.map +1 -0
  152. package/dist/core/source/sparse.d.ts +192 -0
  153. package/dist/core/source/sparse.js +762 -0
  154. package/dist/core/source/sparse.js.map +1 -0
  155. package/dist/core/source/types.d.ts +120 -0
  156. package/dist/core/source/types.js +9 -0
  157. package/dist/core/source/types.js.map +1 -0
  158. package/dist/core/surface/index.d.ts +10 -0
  159. package/dist/core/surface/index.js +9 -0
  160. package/dist/core/surface/index.js.map +1 -0
  161. package/dist/core/surface/level-set-pass.d.ts +140 -0
  162. package/dist/core/surface/level-set-pass.js +291 -0
  163. package/dist/core/surface/level-set-pass.js.map +1 -0
  164. package/dist/core/surface/level-set-wgsl.d.ts +46 -0
  165. package/dist/core/surface/level-set-wgsl.js +99 -0
  166. package/dist/core/surface/level-set-wgsl.js.map +1 -0
  167. package/dist/core/surface/points.d.ts +109 -0
  168. package/dist/core/surface/points.js +226 -0
  169. package/dist/core/surface/points.js.map +1 -0
  170. package/dist/core/types.d.ts +37 -0
  171. package/dist/core/types.js +32 -0
  172. package/dist/core/types.js.map +1 -0
  173. package/dist/core/wgsl/api.d.ts +65 -0
  174. package/dist/core/wgsl/api.js +546 -0
  175. package/dist/core/wgsl/api.js.map +1 -0
  176. package/dist/core/wgsl/generate.d.ts +90 -0
  177. package/dist/core/wgsl/generate.js +678 -0
  178. package/dist/core/wgsl/generate.js.map +1 -0
  179. package/dist/core/wgsl/lean.d.ts +50 -0
  180. package/dist/core/wgsl/lean.js +327 -0
  181. package/dist/core/wgsl/lean.js.map +1 -0
  182. package/dist/core/wgsl/level-set.d.ts +58 -0
  183. package/dist/core/wgsl/level-set.js +200 -0
  184. package/dist/core/wgsl/level-set.js.map +1 -0
  185. package/dist/core/wgsl/majorant.d.ts +62 -0
  186. package/dist/core/wgsl/majorant.js +381 -0
  187. package/dist/core/wgsl/majorant.js.map +1 -0
  188. package/dist/core/wgsl/pnanovdb.chunks.generated.d.ts +14 -0
  189. package/dist/core/wgsl/pnanovdb.chunks.generated.js +333 -0
  190. package/dist/core/wgsl/pnanovdb.chunks.generated.js.map +1 -0
  191. package/dist/core/wgsl/reserved.d.ts +9 -0
  192. package/dist/core/wgsl/reserved.js +26 -0
  193. package/dist/core/wgsl/reserved.js.map +1 -0
  194. package/dist/core/wgsl/types.d.ts +198 -0
  195. package/dist/core/wgsl/types.js +2 -0
  196. package/dist/core/wgsl/types.js.map +1 -0
  197. package/dist/three/coarse-first.d.ts +207 -0
  198. package/dist/three/coarse-first.js +205 -0
  199. package/dist/three/coarse-first.js.map +1 -0
  200. package/dist/three/compute.d.ts +73 -0
  201. package/dist/three/compute.js +66 -0
  202. package/dist/three/compute.js.map +1 -0
  203. package/dist/three/device.d.ts +66 -0
  204. package/dist/three/device.js +62 -0
  205. package/dist/three/device.js.map +1 -0
  206. package/dist/three/frame/core-environment.d.ts +38 -0
  207. package/dist/three/frame/core-environment.js +154 -0
  208. package/dist/three/frame/core-environment.js.map +1 -0
  209. package/dist/three/frame/core-integrate-material.d.ts +34 -0
  210. package/dist/three/frame/core-integrate-material.js +162 -0
  211. package/dist/three/frame/core-integrate-material.js.map +1 -0
  212. package/dist/three/frame/core-occluders.d.ts +53 -0
  213. package/dist/three/frame/core-occluders.js +193 -0
  214. package/dist/three/frame/core-occluders.js.map +1 -0
  215. package/dist/three/frame/core-structs.d.ts +34 -0
  216. package/dist/three/frame/core-structs.js +61 -0
  217. package/dist/three/frame/core-structs.js.map +1 -0
  218. package/dist/three/frame/core-textures.d.ts +41 -0
  219. package/dist/three/frame/core-textures.js +114 -0
  220. package/dist/three/frame/core-textures.js.map +1 -0
  221. package/dist/three/frame/emission-light.d.ts +117 -0
  222. package/dist/three/frame/emission-light.js +276 -0
  223. package/dist/three/frame/emission-light.js.map +1 -0
  224. package/dist/three/frame/index.d.ts +19 -0
  225. package/dist/three/frame/index.js +15 -0
  226. package/dist/three/frame/index.js.map +1 -0
  227. package/dist/three/frame/medium.d.ts +33 -0
  228. package/dist/three/frame/medium.js +29 -0
  229. package/dist/three/frame/medium.js.map +1 -0
  230. package/dist/three/frame/renderer.d.ts +97 -0
  231. package/dist/three/frame/renderer.js +480 -0
  232. package/dist/three/frame/renderer.js.map +1 -0
  233. package/dist/three/frame/spectrum.d.ts +4 -0
  234. package/dist/three/frame/spectrum.js +15 -0
  235. package/dist/three/frame/spectrum.js.map +1 -0
  236. package/dist/three/frame/three-internals.d.ts +60 -0
  237. package/dist/three/frame/three-internals.js +152 -0
  238. package/dist/three/frame/three-internals.js.map +1 -0
  239. package/dist/three/frame/volume-shadows.d.ts +139 -0
  240. package/dist/three/frame/volume-shadows.js +403 -0
  241. package/dist/three/frame/volume-shadows.js.map +1 -0
  242. package/dist/three/frame/volume.d.ts +230 -0
  243. package/dist/three/frame/volume.js +268 -0
  244. package/dist/three/frame/volume.js.map +1 -0
  245. package/dist/three/grid-node.d.ts +229 -0
  246. package/dist/three/grid-node.js +545 -0
  247. package/dist/three/grid-node.js.map +1 -0
  248. package/dist/three/index.d.ts +52 -0
  249. package/dist/three/index.js +58 -0
  250. package/dist/three/index.js.map +1 -0
  251. package/dist/three/internal.d.ts +20 -0
  252. package/dist/three/internal.js +18 -0
  253. package/dist/three/internal.js.map +1 -0
  254. package/dist/three/level-set-material.d.ts +185 -0
  255. package/dist/three/level-set-material.js +241 -0
  256. package/dist/three/level-set-material.js.map +1 -0
  257. package/dist/three/level-set-physical-material.d.ts +154 -0
  258. package/dist/three/level-set-physical-material.js +253 -0
  259. package/dist/three/level-set-physical-material.js.map +1 -0
  260. package/dist/three/level-set-velocity.d.ts +94 -0
  261. package/dist/three/level-set-velocity.js +208 -0
  262. package/dist/three/level-set-velocity.js.map +1 -0
  263. package/dist/three/material.d.ts +324 -0
  264. package/dist/three/material.js +502 -0
  265. package/dist/three/material.js.map +1 -0
  266. package/dist/three/points.d.ts +140 -0
  267. package/dist/three/points.js +261 -0
  268. package/dist/three/points.js.map +1 -0
  269. package/dist/three/sparse-source.d.ts +165 -0
  270. package/dist/three/sparse-source.js +405 -0
  271. package/dist/three/sparse-source.js.map +1 -0
  272. package/dist/three/volume-source.d.ts +22 -0
  273. package/dist/three/volume-source.js +110 -0
  274. package/dist/three/volume-source.js.map +1 -0
  275. package/dist/tools/cpu/brick-atlas.d.ts +36 -0
  276. package/dist/tools/cpu/brick-atlas.js +129 -0
  277. package/dist/tools/cpu/brick-atlas.js.map +1 -0
  278. package/dist/tools/cpu/compute.d.ts +116 -0
  279. package/dist/tools/cpu/compute.js +239 -0
  280. package/dist/tools/cpu/compute.js.map +1 -0
  281. package/dist/tools/cpu/lean-reads.d.ts +81 -0
  282. package/dist/tools/cpu/lean-reads.js +262 -0
  283. package/dist/tools/cpu/lean-reads.js.map +1 -0
  284. package/dist/tools/cpu/level-set.d.ts +111 -0
  285. package/dist/tools/cpu/level-set.js +313 -0
  286. package/dist/tools/cpu/level-set.js.map +1 -0
  287. package/dist/tools/cpu/majorant.d.ts +265 -0
  288. package/dist/tools/cpu/majorant.js +541 -0
  289. package/dist/tools/cpu/majorant.js.map +1 -0
  290. package/dist/tools/cpu/march.d.ts +297 -0
  291. package/dist/tools/cpu/march.js +726 -0
  292. package/dist/tools/cpu/march.js.map +1 -0
  293. package/dist/tools/cpu/mesh-decimate.d.ts +124 -0
  294. package/dist/tools/cpu/mesh-decimate.js +1225 -0
  295. package/dist/tools/cpu/mesh-decimate.js.map +1 -0
  296. package/dist/tools/cpu/points.d.ts +29 -0
  297. package/dist/tools/cpu/points.js +38 -0
  298. package/dist/tools/cpu/points.js.map +1 -0
  299. package/dist/tools/cpu/probe-coords.d.ts +70 -0
  300. package/dist/tools/cpu/probe-coords.js +116 -0
  301. package/dist/tools/cpu/probe-coords.js.map +1 -0
  302. package/dist/tools/cpu/read-value.d.ts +44 -0
  303. package/dist/tools/cpu/read-value.js +351 -0
  304. package/dist/tools/cpu/read-value.js.map +1 -0
  305. package/dist/tools/cpu/sample-trilinear.d.ts +43 -0
  306. package/dist/tools/cpu/sample-trilinear.js +168 -0
  307. package/dist/tools/cpu/sample-trilinear.js.map +1 -0
  308. package/dist/tools/cpu/stride-tables.d.ts +56 -0
  309. package/dist/tools/cpu/stride-tables.generated.d.ts +1059 -0
  310. package/dist/tools/cpu/stride-tables.generated.js +1267 -0
  311. package/dist/tools/cpu/stride-tables.generated.js.map +1 -0
  312. package/dist/tools/cpu/stride-tables.js +78 -0
  313. package/dist/tools/cpu/stride-tables.js.map +1 -0
  314. package/dist/tools/cpu/surface-nets.d.ts +90 -0
  315. package/dist/tools/cpu/surface-nets.js +597 -0
  316. package/dist/tools/cpu/surface-nets.js.map +1 -0
  317. package/dist/tools/errors.d.ts +66 -0
  318. package/dist/tools/errors.js +67 -0
  319. package/dist/tools/errors.js.map +1 -0
  320. package/dist/tools/frame/ambient.d.ts +98 -0
  321. package/dist/tools/frame/ambient.js +274 -0
  322. package/dist/tools/frame/ambient.js.map +1 -0
  323. package/dist/tools/frame/blackbody.d.ts +57 -0
  324. package/dist/tools/frame/blackbody.js +151 -0
  325. package/dist/tools/frame/blackbody.js.map +1 -0
  326. package/dist/tools/frame/brick-cache.d.ts +165 -0
  327. package/dist/tools/frame/brick-cache.js +326 -0
  328. package/dist/tools/frame/brick-cache.js.map +1 -0
  329. package/dist/tools/frame/emission.d.ts +137 -0
  330. package/dist/tools/frame/emission.js +290 -0
  331. package/dist/tools/frame/emission.js.map +1 -0
  332. package/dist/tools/frame/environment-gpu.d.ts +111 -0
  333. package/dist/tools/frame/environment-gpu.js +280 -0
  334. package/dist/tools/frame/environment-gpu.js.map +1 -0
  335. package/dist/tools/frame/environment.d.ts +106 -0
  336. package/dist/tools/frame/environment.js +272 -0
  337. package/dist/tools/frame/environment.js.map +1 -0
  338. package/dist/tools/frame/froxel.d.ts +58 -0
  339. package/dist/tools/frame/froxel.js +115 -0
  340. package/dist/tools/frame/froxel.js.map +1 -0
  341. package/dist/tools/frame/grid.d.ts +392 -0
  342. package/dist/tools/frame/grid.js +802 -0
  343. package/dist/tools/frame/grid.js.map +1 -0
  344. package/dist/tools/frame/index.d.ts +150 -0
  345. package/dist/tools/frame/index.js +389 -0
  346. package/dist/tools/frame/index.js.map +1 -0
  347. package/dist/tools/frame/medium.d.ts +77 -0
  348. package/dist/tools/frame/medium.js +101 -0
  349. package/dist/tools/frame/medium.js.map +1 -0
  350. package/dist/tools/frame/mie-table.d.ts +6 -0
  351. package/dist/tools/frame/mie-table.js +16 -0
  352. package/dist/tools/frame/mie-table.js.map +1 -0
  353. package/dist/tools/frame/mie.d.ts +63 -0
  354. package/dist/tools/frame/mie.js +194 -0
  355. package/dist/tools/frame/mie.js.map +1 -0
  356. package/dist/tools/frame/mlp-nn.d.ts +36 -0
  357. package/dist/tools/frame/mlp-nn.js +159 -0
  358. package/dist/tools/frame/mlp-nn.js.map +1 -0
  359. package/dist/tools/frame/mlp-tza.d.ts +29 -0
  360. package/dist/tools/frame/mlp-tza.js +186 -0
  361. package/dist/tools/frame/mlp-tza.js.map +1 -0
  362. package/dist/tools/frame/mlp.d.ts +183 -0
  363. package/dist/tools/frame/mlp.js +434 -0
  364. package/dist/tools/frame/mlp.js.map +1 -0
  365. package/dist/tools/frame/ms-exit.d.ts +42 -0
  366. package/dist/tools/frame/ms-exit.js +90 -0
  367. package/dist/tools/frame/ms-exit.js.map +1 -0
  368. package/dist/tools/frame/multi-scale.d.ts +152 -0
  369. package/dist/tools/frame/multi-scale.js +302 -0
  370. package/dist/tools/frame/multi-scale.js.map +1 -0
  371. package/dist/tools/frame/neural-weights.d.ts +10 -0
  372. package/dist/tools/frame/neural-weights.js +244 -0
  373. package/dist/tools/frame/neural-weights.js.map +1 -0
  374. package/dist/tools/frame/neural.d.ts +80 -0
  375. package/dist/tools/frame/neural.js +150 -0
  376. package/dist/tools/frame/neural.js.map +1 -0
  377. package/dist/tools/frame/occluders.d.ts +51 -0
  378. package/dist/tools/frame/occluders.js +72 -0
  379. package/dist/tools/frame/occluders.js.map +1 -0
  380. package/dist/tools/frame/pyramid-layout.d.ts +55 -0
  381. package/dist/tools/frame/pyramid-layout.js +100 -0
  382. package/dist/tools/frame/pyramid-layout.js.map +1 -0
  383. package/dist/tools/frame/shadows.d.ts +190 -0
  384. package/dist/tools/frame/shadows.js +468 -0
  385. package/dist/tools/frame/shadows.js.map +1 -0
  386. package/dist/tools/frame/sparse.d.ts +147 -0
  387. package/dist/tools/frame/sparse.js +432 -0
  388. package/dist/tools/frame/sparse.js.map +1 -0
  389. package/dist/tools/frame/spectral-stack.d.ts +159 -0
  390. package/dist/tools/frame/spectral-stack.js +391 -0
  391. package/dist/tools/frame/spectral-stack.js.map +1 -0
  392. package/dist/tools/frame/spectral.d.ts +222 -0
  393. package/dist/tools/frame/spectral.js +572 -0
  394. package/dist/tools/frame/spectral.js.map +1 -0
  395. package/dist/tools/frame/stack.d.ts +115 -0
  396. package/dist/tools/frame/stack.js +290 -0
  397. package/dist/tools/frame/stack.js.map +1 -0
  398. package/dist/tools/frame/view.d.ts +131 -0
  399. package/dist/tools/frame/view.js +337 -0
  400. package/dist/tools/frame/view.js.map +1 -0
  401. package/dist/tools/index.d.ts +157 -0
  402. package/dist/tools/index.js +132 -0
  403. package/dist/tools/index.js.map +1 -0
  404. package/dist/tools/internal.d.ts +87 -0
  405. package/dist/tools/internal.js +85 -0
  406. package/dist/tools/internal.js.map +1 -0
  407. package/dist/tools/nanovdb/build-from-vdb.d.ts +59 -0
  408. package/dist/tools/nanovdb/build-from-vdb.js +100 -0
  409. package/dist/tools/nanovdb/build-from-vdb.js.map +1 -0
  410. package/dist/tools/nanovdb/bytes.d.ts +233 -0
  411. package/dist/tools/nanovdb/bytes.js +388 -0
  412. package/dist/tools/nanovdb/bytes.js.map +1 -0
  413. package/dist/tools/nanovdb/coarse-first.d.ts +78 -0
  414. package/dist/tools/nanovdb/coarse-first.js +92 -0
  415. package/dist/tools/nanovdb/coarse-first.js.map +1 -0
  416. package/dist/tools/nanovdb/half.d.ts +22 -0
  417. package/dist/tools/nanovdb/half.js +73 -0
  418. package/dist/tools/nanovdb/half.js.map +1 -0
  419. package/dist/tools/nanovdb/index.d.ts +34 -0
  420. package/dist/tools/nanovdb/index.js +25 -0
  421. package/dist/tools/nanovdb/index.js.map +1 -0
  422. package/dist/tools/nanovdb/inspect.d.ts +33 -0
  423. package/dist/tools/nanovdb/inspect.js +70 -0
  424. package/dist/tools/nanovdb/inspect.js.map +1 -0
  425. package/dist/tools/nanovdb/leaf-codec.d.ts +119 -0
  426. package/dist/tools/nanovdb/leaf-codec.js +356 -0
  427. package/dist/tools/nanovdb/leaf-codec.js.map +1 -0
  428. package/dist/tools/nanovdb/quantize.d.ts +72 -0
  429. package/dist/tools/nanovdb/quantize.js +329 -0
  430. package/dist/tools/nanovdb/quantize.js.map +1 -0
  431. package/dist/tools/nanovdb/resample.d.ts +177 -0
  432. package/dist/tools/nanovdb/resample.js +692 -0
  433. package/dist/tools/nanovdb/resample.js.map +1 -0
  434. package/dist/tools/nanovdb/serialize.d.ts +176 -0
  435. package/dist/tools/nanovdb/serialize.js +439 -0
  436. package/dist/tools/nanovdb/serialize.js.map +1 -0
  437. package/dist/tools/nanovdb/stats.d.ts +87 -0
  438. package/dist/tools/nanovdb/stats.js +225 -0
  439. package/dist/tools/nanovdb/stats.js.map +1 -0
  440. package/dist/tools/nanovdb/transform.d.ts +30 -0
  441. package/dist/tools/nanovdb/transform.js +94 -0
  442. package/dist/tools/nanovdb/transform.js.map +1 -0
  443. package/dist/tools/nanovdb/tree.d.ts +186 -0
  444. package/dist/tools/nanovdb/tree.js +530 -0
  445. package/dist/tools/nanovdb/tree.js.map +1 -0
  446. package/dist/tools/nanovdb/write-nvdb.d.ts +74 -0
  447. package/dist/tools/nanovdb/write-nvdb.js +290 -0
  448. package/dist/tools/nanovdb/write-nvdb.js.map +1 -0
  449. package/dist/tools/nvdb-file.d.ts +265 -0
  450. package/dist/tools/nvdb-file.js +763 -0
  451. package/dist/tools/nvdb-file.js.map +1 -0
  452. package/dist/tools/nvdb-stream.d.ts +154 -0
  453. package/dist/tools/nvdb-stream.js +409 -0
  454. package/dist/tools/nvdb-stream.js.map +1 -0
  455. package/dist/tools/reference/analytic.d.ts +41 -0
  456. package/dist/tools/reference/analytic.js +95 -0
  457. package/dist/tools/reference/analytic.js.map +1 -0
  458. package/dist/tools/reference/environment.d.ts +62 -0
  459. package/dist/tools/reference/environment.js +154 -0
  460. package/dist/tools/reference/environment.js.map +1 -0
  461. package/dist/tools/reference/index.d.ts +12 -0
  462. package/dist/tools/reference/index.js +13 -0
  463. package/dist/tools/reference/index.js.map +1 -0
  464. package/dist/tools/reference/media.d.ts +14 -0
  465. package/dist/tools/reference/media.js +30 -0
  466. package/dist/tools/reference/media.js.map +1 -0
  467. package/dist/tools/reference/rng.d.ts +20 -0
  468. package/dist/tools/reference/rng.js +30 -0
  469. package/dist/tools/reference/rng.js.map +1 -0
  470. package/dist/tools/reference/scene.d.ts +312 -0
  471. package/dist/tools/reference/scene.js +169 -0
  472. package/dist/tools/reference/scene.js.map +1 -0
  473. package/dist/tools/reference/tables.d.ts +98 -0
  474. package/dist/tools/reference/tables.js +264 -0
  475. package/dist/tools/reference/tables.js.map +1 -0
  476. package/dist/tools/reference/trace.d.ts +160 -0
  477. package/dist/tools/reference/trace.js +497 -0
  478. package/dist/tools/reference/trace.js.map +1 -0
  479. package/dist/tools/vdb/bit-utils.d.ts +20 -0
  480. package/dist/tools/vdb/bit-utils.js +42 -0
  481. package/dist/tools/vdb/bit-utils.js.map +1 -0
  482. package/dist/tools/vdb/blosc-write.d.ts +43 -0
  483. package/dist/tools/vdb/blosc-write.js +197 -0
  484. package/dist/tools/vdb/blosc-write.js.map +1 -0
  485. package/dist/tools/vdb/blosc.d.ts +86 -0
  486. package/dist/tools/vdb/blosc.js +287 -0
  487. package/dist/tools/vdb/blosc.js.map +1 -0
  488. package/dist/tools/vdb/blosclz.d.ts +33 -0
  489. package/dist/tools/vdb/blosclz.js +112 -0
  490. package/dist/tools/vdb/blosclz.js.map +1 -0
  491. package/dist/tools/vdb/byte-reader.d.ts +50 -0
  492. package/dist/tools/vdb/byte-reader.js +161 -0
  493. package/dist/tools/vdb/byte-reader.js.map +1 -0
  494. package/dist/tools/vdb/compression.d.ts +81 -0
  495. package/dist/tools/vdb/compression.js +260 -0
  496. package/dist/tools/vdb/compression.js.map +1 -0
  497. package/dist/tools/vdb/errors.d.ts +10 -0
  498. package/dist/tools/vdb/errors.js +11 -0
  499. package/dist/tools/vdb/errors.js.map +1 -0
  500. package/dist/tools/vdb/grid.d.ts +37 -0
  501. package/dist/tools/vdb/grid.js +153 -0
  502. package/dist/tools/vdb/grid.js.map +1 -0
  503. package/dist/tools/vdb/half-float.d.ts +9 -0
  504. package/dist/tools/vdb/half-float.js +24 -0
  505. package/dist/tools/vdb/half-float.js.map +1 -0
  506. package/dist/tools/vdb/index.d.ts +4 -0
  507. package/dist/tools/vdb/index.js +3 -0
  508. package/dist/tools/vdb/index.js.map +1 -0
  509. package/dist/tools/vdb/inflate.d.ts +24 -0
  510. package/dist/tools/vdb/inflate.js +334 -0
  511. package/dist/tools/vdb/inflate.js.map +1 -0
  512. package/dist/tools/vdb/lz4.d.ts +30 -0
  513. package/dist/tools/vdb/lz4.js +228 -0
  514. package/dist/tools/vdb/lz4.js.map +1 -0
  515. package/dist/tools/vdb/metadata.d.ts +17 -0
  516. package/dist/tools/vdb/metadata.js +72 -0
  517. package/dist/tools/vdb/metadata.js.map +1 -0
  518. package/dist/tools/vdb/parse.d.ts +47 -0
  519. package/dist/tools/vdb/parse.js +241 -0
  520. package/dist/tools/vdb/parse.js.map +1 -0
  521. package/dist/tools/vdb/point-render-data.d.ts +79 -0
  522. package/dist/tools/vdb/point-render-data.js +137 -0
  523. package/dist/tools/vdb/point-render-data.js.map +1 -0
  524. package/dist/tools/vdb/points.d.ts +186 -0
  525. package/dist/tools/vdb/points.js +835 -0
  526. package/dist/tools/vdb/points.js.map +1 -0
  527. package/dist/tools/vdb/transform.d.ts +23 -0
  528. package/dist/tools/vdb/transform.js +54 -0
  529. package/dist/tools/vdb/transform.js.map +1 -0
  530. package/dist/tools/vdb/tree.d.ts +111 -0
  531. package/dist/tools/vdb/tree.js +228 -0
  532. package/dist/tools/vdb/tree.js.map +1 -0
  533. package/dist/tools/vdb/types.d.ts +195 -0
  534. package/dist/tools/vdb/types.js +3 -0
  535. package/dist/tools/vdb/types.js.map +1 -0
  536. package/dist/tools/wvdb/bake.d.ts +145 -0
  537. package/dist/tools/wvdb/bake.js +361 -0
  538. package/dist/tools/wvdb/bake.js.map +1 -0
  539. package/dist/tools/wvdb/dense.d.ts +191 -0
  540. package/dist/tools/wvdb/dense.js +368 -0
  541. package/dist/tools/wvdb/dense.js.map +1 -0
  542. package/dist/tools/wvdb/format.d.ts +220 -0
  543. package/dist/tools/wvdb/format.js +306 -0
  544. package/dist/tools/wvdb/format.js.map +1 -0
  545. package/dist/tools/wvdb/index.d.ts +14 -0
  546. package/dist/tools/wvdb/index.js +15 -0
  547. package/dist/tools/wvdb/index.js.map +1 -0
  548. package/dist/tools/wvdb/level-set.d.ts +56 -0
  549. package/dist/tools/wvdb/level-set.js +153 -0
  550. package/dist/tools/wvdb/level-set.js.map +1 -0
  551. package/dist/tools/wvdb/nanovdb.d.ts +59 -0
  552. package/dist/tools/wvdb/nanovdb.js +64 -0
  553. package/dist/tools/wvdb/nanovdb.js.map +1 -0
  554. package/dist/tools/wvdb/partial.d.ts +74 -0
  555. package/dist/tools/wvdb/partial.js +233 -0
  556. package/dist/tools/wvdb/partial.js.map +1 -0
  557. package/dist/tools/wvdb/read.d.ts +336 -0
  558. package/dist/tools/wvdb/read.js +766 -0
  559. package/dist/tools/wvdb/read.js.map +1 -0
  560. package/dist/tools/wvdb/sha256.d.ts +7 -0
  561. package/dist/tools/wvdb/sha256.js +76 -0
  562. package/dist/tools/wvdb/sha256.js.map +1 -0
  563. package/dist/tools/wvdb/write.d.ts +149 -0
  564. package/dist/tools/wvdb/write.js +403 -0
  565. package/dist/tools/wvdb/write.js.map +1 -0
  566. package/package.json +83 -4
  567. package/vendor/LICENSE +201 -0
  568. package/vendor/NOTICE +19 -0
  569. package/vendor/VENDOR.md +100 -0
  570. package/vendor/pnanovdb.wgsl +1577 -0
@@ -0,0 +1,405 @@
1
+ // Portions derived from mjurczyk/openvdb (MIT), commit 75e7345 (v0.26.0): the source half of createVolumeUniforms /
2
+ // createVolumeNodes (frameShaderChunks.js L729–763, L834–1028), whose sparse-grid port (the TSL half) was deleted in K6.11
3
+ // (D35); this file is the handle the core's sparse source is made from.
4
+ // Copyright (c) mjurczyk/openvdb contributors. Licensed under the MIT License (see THIRD_PARTY_NOTICES.md).
5
+ // Divergences: DIVERGES.md (K3.2 rows), V23–V25, V145.
6
+ /**
7
+ * The sparse volume source (K3.2, R1 §4.2–4.3): a `VDBGridPool` grid behind the same seam as the
8
+ * dense `.wvdb` source, so `VDBFrameVolume` renders NanoVDB grids.
9
+ *
10
+ * const grids = new VDBGridNode(renderer, pool, { profile: "march", helpers: ["cellBoundTrilinear", "hddaCellEnd", "nodeAverage", "fastTrilinear"] });
11
+ * const source = vdbSparseSource(grids, { density: id }, { lod: "coarse-pyramid", images: { density: image } });
12
+ * const volume = new VDBFrameVolume(source, { extinction: 100 }); // box: the grid's world box
13
+ *
14
+ * K6.8a / K6.11: the source is a handle (grids, ids, options, boxes, stats, the image-follow state). `VDBFrameRenderer`
15
+ * reads it into the core's sparse source (`vdbSparseSource`), which builds its own pyramids and reads the grids itself.
16
+ * The handle holds no GPU object. (Custom TSL materials sample a pooled grid through `VDBGridNode`; custom WGSL or compute
17
+ * uses the core source's `wgsl()`.)
18
+ *
19
+ * Positions are his local unit box [-0.5, 0.5]³; uvw = local + 0.5 (+ offset, wrapped) maps onto the
20
+ * channel grid's index cell box `[min − ½, max + ½]` (voxel centres at integers), so uvw
21
+ * (i + 0.5) / N lands on voxel min + i as on a dense texel centre. The sample position is clamped to
22
+ * `[min, max]` (his clamp-to-edge). Level 0 is the pool's trilinear sample; with the node helper
23
+ * `'fastTrilinear'` (recommended, K3.2d) it is `vdbSampleFast` through one accessor per shader invocation
24
+ * (`cacheAccessor`): the same values, 1.5–2× faster on the hardware GPU (docs/archive/handoffs/K3-2d.md). (The core's
25
+ * sparse source reads these options.)
26
+ *
27
+ * LOD (`lod`, his `sampleExtinction(localPos, lod)` at lod ≥ 1; R1 §4.3):
28
+ * - `'none'`: level 0 always (no prefilter; aliases when a froxel spans many voxels). lodLevels 0.
29
+ * - `'coarse-pyramid'` (default, the K3.2 A/B pick): a dense r16f pyramid from L₀ = max(1, ⌈log2(maxTexels / pyramidMax)⌉):
30
+ * the base is a box resample of the grid, the levels above it his box mip atlas. lod in (0, L₀)
31
+ * blends level 0 toward L₀; lod ≥ L₀ samples the pyramid as his mip atlas. GPU bytes: ~2 B × (base
32
+ * + atlas) texels. The core's sparse source builds it on the GPU from the pool grid (K3.2a: the core's
33
+ * `vdbCreateBoxPyramid`, no CPU image needed) and rebuilds it when the grid's image changes
34
+ * (`pool.replace`: a sequence frame). K6.11: the CPU build (`pyramidBuild: 'cpu'`, the three textures' static path) is
35
+ * deleted; `@pmndrs/vdb/tools` `vdbBoxPyramid` stays the GPU build's CPU twin.
36
+ * - `'node-average'`: no extra memory: trilinear over the node averages (`vdbNodeAverage`) at
37
+ * level 3 (leaves, the exact 8³ box mean for fog leaves) and level 7 (lower nodes, the mean of
38
+ * their active voxels); lod in (0, 3) blends level 0 → 3, (3, 7) blends 3 → 7. Needs stats.
39
+ *
40
+ * HDDA: `skipEmpty` lets a march jump samples that are provably 0 (`VDBFrameVolume` `hdda`, default
41
+ * off since D30 / D31: it slowed the shadow march on Apple GPUs; the image is the same either way).
42
+ *
43
+ * Following the image (`followImage`, G16a): the index boxes, world box and pyramid are fixed when the source is
44
+ * made unless it follows the grids' images. Then a `pool.replace` that changes a channel grid's box (a coarse-first
45
+ * swap: the preview, then the full grid in the same id) is re-read from `pool.info` once the new image is resident:
46
+ * the new layout, the LOD range and a new `version`, which a `VDBFrameVolume` follows with its box. No shader is rebuilt.
47
+ *
48
+ * Mask, albedo and emission grids (optional, scalar; albedo may be three grids for RGB) are read at
49
+ * level 0 only. One VDB module per shader: every grid goes through the one `VDBGridNode`.
50
+ */
51
+ import { VDBError } from "../core/errors.js";
52
+ import { vdbBoxPyramidLayout } from "../tools/frame/pyramid-layout.js";
53
+ import { leafVoxels, treeNodes } from "../tools/cpu/march.js";
54
+ const bad = (message) => new VDBError("VDB_BAD_OPTION", `vdbSparseSource: ${message}`);
55
+ /** The non-zero density stats of an image (all leaf voxels, active or not, and active tiles). */
56
+ function imageStats(image, clamp01) {
57
+ let sum = 0;
58
+ let count = 0;
59
+ let maxValue = 0;
60
+ const add = (v, n) => {
61
+ const x = clamp01 ? Math.min(Math.max(v, 0), 1) : v;
62
+ if (x !== 0) {
63
+ sum += x * n;
64
+ count += n;
65
+ maxValue = Math.max(maxValue, x);
66
+ }
67
+ };
68
+ for (const node of treeNodes(image)) {
69
+ for (const t of node.activeTiles)
70
+ add(t.value, t.dim ** 3);
71
+ if (node.level !== 0)
72
+ continue;
73
+ const { values } = leafVoxels(image, node.address);
74
+ for (let n = 0; n < 512; n++)
75
+ add(values[n], 1);
76
+ }
77
+ return { meanNonZero: count > 0 ? sum / count : 0, max: maxValue, activeVoxels: count };
78
+ }
79
+ /** World AABB of an index cell box through a 3x4 row-major affine. */
80
+ function worldBox(box, m) {
81
+ const lo = [Infinity, Infinity, Infinity];
82
+ const hi = [-Infinity, -Infinity, -Infinity];
83
+ for (let c = 0; c < 8; c++) {
84
+ const p = [c & 1 ? box.max[0] + 0.5 : box.min[0] - 0.5, c & 2 ? box.max[1] + 0.5 : box.min[1] - 0.5, c & 4 ? box.max[2] + 0.5 : box.min[2] - 0.5];
85
+ for (let r = 0; r < 3; r++) {
86
+ const v = m[r * 4] * p[0] + m[r * 4 + 1] * p[1] + m[r * 4 + 2] * p[2] + m[r * 4 + 3];
87
+ lo[r] = Math.min(lo[r], v);
88
+ hi[r] = Math.max(hi[r], v);
89
+ }
90
+ }
91
+ return [lo, hi];
92
+ }
93
+ /** Local unit box → sample index space: p = min − ½ + (local + ½)·size (column-major). */
94
+ function boxToSourceOf(b, texels) {
95
+ const [sx, sy, sz] = texels;
96
+ return new Float32Array([sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, sz, 0, b.min[0] - 0.5 + 0.5 * sx, b.min[1] - 0.5 + 0.5 * sy, b.min[2] - 0.5 + 0.5 * sz, 1]);
97
+ }
98
+ const texelsOf = (b) => [b.max[0] - b.min[0] + 1, b.max[1] - b.min[1] + 1, b.max[2] - b.min[2] + 1];
99
+ /**
100
+ * The handle (K6.8a): grids, ids, options, boxes, stats and the image-follow state. The frame renderer reads these into
101
+ * the core's sparse source.
102
+ */
103
+ class SparseSource {
104
+ kind = "sparse";
105
+ grids;
106
+ ids;
107
+ lod;
108
+ normalize;
109
+ channels;
110
+ // G16a: the layout fields below are re-read after an image change when `followImage` is on.
111
+ indexBox;
112
+ auxBoxes;
113
+ texels;
114
+ lodLevels;
115
+ stats;
116
+ statsUpdates = 0;
117
+ boxToSource;
118
+ bbox;
119
+ fastTrilinear;
120
+ cacheAccessor;
121
+ followImage;
122
+ pyramidOptions;
123
+ /** K3.2f (internal): the core source's brick cache. */
124
+ brickCache;
125
+ /** K3.2f-e (internal): the core source's other brick options (validated by the core source). */
126
+ brickOptions;
127
+ layoutUpdates = 0;
128
+ /** G16a: the newest channel imageRevision the layout describes, the pool revision last checked. */
129
+ #layoutRevision = -1;
130
+ #layoutPoolRevision = -1;
131
+ #poolIds;
132
+ #versionSeen = { poolRevision: -1, value: 0 };
133
+ /** K3.2e: the density imageRevision the stats describe, the pool revision last checked, and a readback in flight. */
134
+ #statsRevision = -1;
135
+ #statsPoolRevisionSeen = -1;
136
+ #statsReadback = null;
137
+ constructor(grids, ids, o) {
138
+ const pool = grids.pool;
139
+ if (typeof pool.info !== "function")
140
+ throw bad("the VDBGridNode's pool has no info(); pass a VDBGridPool.");
141
+ const info = (id) => pool.info(id);
142
+ const lod = o.lod ?? "coarse-pyramid";
143
+ if (lod !== "none" && lod !== "coarse-pyramid" && lod !== "node-average")
144
+ throw bad(`unknown lod ${JSON.stringify(lod)}; use 'none', 'coarse-pyramid' or 'node-average'.`);
145
+ const normalize = o.normalize ?? "none";
146
+ if (normalize !== "none" && normalize !== "clamp01")
147
+ throw bad(`unknown normalize ${JSON.stringify(normalize)}; use 'none' or 'clamp01'.`);
148
+ const helpers = new Set(grids.options.helpers ?? []);
149
+ if (grids.options.profile !== "march" || !helpers.has("cellBoundTrilinear") || !helpers.has("hddaCellEnd") || (lod === "node-average" && !helpers.has("nodeAverage"))) {
150
+ throw bad(`make the VDBGridNode with profile 'march' and helpers ['cellBoundTrilinear', 'hddaCellEnd'${lod === "node-average" ? ", 'nodeAverage'" : ""}] ` +
151
+ `(got profile '${grids.options.profile}', helpers [${[...helpers].join(", ")}]).`);
152
+ }
153
+ const fastTrilinear = o.fastTrilinear ?? helpers.has("fastTrilinear");
154
+ if (fastTrilinear && !helpers.has("fastTrilinear"))
155
+ throw bad("fastTrilinear needs the VDBGridNode helper 'fastTrilinear' (add it to helpers), or pass fastTrilinear: false.");
156
+ if (fastTrilinear && grids.options.sampler === "nearest")
157
+ throw bad("fastTrilinear needs the VDBGridNode's sampler 'trilinear'.");
158
+ this.fastTrilinear = fastTrilinear;
159
+ this.cacheAccessor = o.cacheAccessor ?? true;
160
+ const brickCache = o.brickCache ?? "off";
161
+ if (brickCache !== "off" && brickCache !== "f32" && brickCache !== "f16")
162
+ throw bad(`brickCache must be 'off', 'f32' or 'f16', got ${JSON.stringify(brickCache)}.`);
163
+ this.brickCache = brickCache;
164
+ const io = o;
165
+ this.brickOptions = Object.freeze({
166
+ ...(io.brickKernels !== undefined ? { brickKernels: io.brickKernels } : {}),
167
+ ...(io.brickMarkStats !== undefined ? { brickMarkStats: io.brickMarkStats } : {}),
168
+ ...(io.brickCapacity !== undefined ? { brickCapacity: io.brickCapacity } : {}),
169
+ ...(io.brickBudget !== undefined ? { brickBudget: io.brickBudget } : {}),
170
+ });
171
+ const followImage = o.followImage ?? false;
172
+ if (typeof followImage !== "boolean")
173
+ throw bad("followImage must be a boolean.");
174
+ if (followImage) {
175
+ const fixed = ["indexBox", "auxIndexBoxes", "bbox"].filter((k) => o[k] !== undefined);
176
+ if (fixed.length)
177
+ throw bad(`followImage re-reads every box from the pool; drop ${fixed.join(", ")} (fixed boxes).`);
178
+ }
179
+ this.followImage = followImage;
180
+ const density = info(ids.density);
181
+ if (lod === "node-average" && !density.hasStats)
182
+ throw bad("lod 'node-average' reads node statistics; this grid has none (rebuild it with stats).");
183
+ this.grids = grids;
184
+ const channelIds = [ids.density, ids.mask, ids.emission, ...(Array.isArray(ids.albedo) ? ids.albedo : [ids.albedo])].filter((v) => v !== undefined);
185
+ this.checkTypes(channelIds.map((id) => ({ id, type: info(id).type })), "a channel grid");
186
+ this.ids = Object.freeze({ ...ids, ...(Array.isArray(ids.albedo) ? { albedo: [...ids.albedo] } : {}) });
187
+ this.lod = lod;
188
+ this.normalize = normalize;
189
+ this.indexBox = o.indexBox ? { min: [...o.indexBox.min], max: [...o.indexBox.max] } : { min: [...density.indexBBox.min], max: [...density.indexBBox.max] };
190
+ const albedoId = Array.isArray(ids.albedo) ? ids.albedo[0] : ids.albedo;
191
+ const box = (id, given) => id === undefined ? null : given ? { min: [...given.min], max: [...given.max] } : { min: [...info(id).indexBBox.min], max: [...info(id).indexBBox.max] };
192
+ const aux = o.auxIndexBoxes ?? {};
193
+ this.auxBoxes = { mask: box(ids.mask, aux.mask), albedo: box(albedoId, aux.albedo), emission: box(ids.emission, aux.emission) };
194
+ this.channels = { mask: ids.mask !== undefined, albedo: ids.albedo !== undefined, emission: ids.emission !== undefined };
195
+ const b = this.indexBox;
196
+ this.texels = texelsOf(b);
197
+ if (this.texels.some((t) => !(t > 0)))
198
+ throw bad("the density index box is empty.");
199
+ const image = o.images?.density;
200
+ if (o.stats)
201
+ this.stats = { ...o.stats };
202
+ else if (image)
203
+ this.stats = imageStats(image, normalize === "clamp01");
204
+ else
205
+ throw bad("pass images.density (the CPU image, for the density stats) or stats.");
206
+ this.#statsRevision = density.imageRevision ?? -1;
207
+ this.boxToSource = boxToSourceOf(b, this.texels);
208
+ this.bbox = o.bbox ? [[...o.bbox[0]], [...o.bbox[1]]] : worldBox(b, density.indexToWorld);
209
+ this.pyramidOptions = o.pyramidMax !== undefined ? { pyramidMax: o.pyramidMax } : {};
210
+ this.lodLevels = this.#lodLevelsOf(this.texels);
211
+ this.#poolIds = [...new Set(channelIds)];
212
+ this.#layoutRevision = this.#poolIds.reduce((r, id) => Math.max(r, info(id).imageRevision ?? 0), 0);
213
+ }
214
+ /** The LOD range: 0 (`'none'`), 7 (`'node-average'`), the pyramid layout's levels (`'coarse-pyramid'`). */
215
+ #lodLevelsOf(texels) {
216
+ if (this.lod === "none")
217
+ return 0;
218
+ if (this.lod === "node-average")
219
+ return 7;
220
+ const { pyramidMax } = this.pyramidOptions;
221
+ return vdbBoxPyramidLayout(texels, pyramidMax !== undefined ? { pyramidMax } : {}).lodLevels;
222
+ }
223
+ /** GPU bytes of the channel grids' pool ranges. */
224
+ get gpuBytes() {
225
+ const pool = this.grids.pool;
226
+ let bytes = 0;
227
+ for (const id of this.#poolIds) {
228
+ try {
229
+ bytes += pool.info(id).capacity;
230
+ }
231
+ catch {
232
+ // A removed grid holds no pool range.
233
+ }
234
+ }
235
+ return { pool: bytes };
236
+ }
237
+ /**
238
+ * G16a (`followImage`): re-reads the layout when a channel grid's image changed and every channel grid is resident
239
+ * again (the update that writes the new image has run: the GPU must not read it through the old boxes, nor the
240
+ * old image through the new ones). Cheap when the pool's revision did not move; called from `version` (a
241
+ * `VDBFrameVolume` asks once per frame, before it places its box) and from the render updates.
242
+ */
243
+ syncLayout() {
244
+ if (!this.followImage)
245
+ return false;
246
+ const pool = this.grids.pool;
247
+ if (typeof pool.revision !== "number" || pool.revision === this.#layoutPoolRevision)
248
+ return false;
249
+ let revision = 0;
250
+ let resident = true;
251
+ const infos = [];
252
+ for (const id of this.#poolIds) {
253
+ let i;
254
+ try {
255
+ i = pool.info(id);
256
+ }
257
+ catch {
258
+ return false; // a removed grid: keep the last layout
259
+ }
260
+ revision = Math.max(revision, i.imageRevision ?? 0);
261
+ if (i.resident === false)
262
+ resident = false;
263
+ infos.push({ id, type: i.type });
264
+ }
265
+ if (revision === this.#layoutRevision) {
266
+ this.#layoutPoolRevision = pool.revision;
267
+ return false;
268
+ }
269
+ if (!resident)
270
+ return false; // look again once the update has written it
271
+ // A new image of a type the module does not decode would read 0 through the new boxes, silently: say so instead
272
+ // (every call until the source is remade over a node that compiles it).
273
+ this.checkTypes(infos, "a channel grid's new image");
274
+ this.#relayout();
275
+ this.#layoutRevision = revision;
276
+ this.#layoutPoolRevision = pool.revision;
277
+ return true;
278
+ }
279
+ /**
280
+ * Throws `VDB_TYPE_NOT_COMPILED` when a channel grid's type is not among the `VDBGridNode`'s compiled `types` (those
281
+ * grids read 0). A node stand-in without `options.types` is not checked.
282
+ */
283
+ checkTypes(infos, what) {
284
+ const compiled = this.grids.options.types;
285
+ if (!compiled)
286
+ return;
287
+ const missing = infos.filter((i) => !compiled.includes(i.type));
288
+ if (missing.length === 0)
289
+ return;
290
+ throw new VDBError("VDB_TYPE_NOT_COMPILED", `vdbSparseSource: ${what} is ${missing.map((m) => `grid ${m.id}: ${m.type}`).join(", ")}, but the VDBGridNode compiles only ` +
291
+ `${compiled.join(", ")}; it would read 0. Make the VDBGridNode with types that include every type the images will have ` +
292
+ `(a coarse-first stream lists them in VDBCoarseFirstEvent.types: types: event.types), then make the source over it.`);
293
+ }
294
+ #relayout() {
295
+ const pool = this.grids.pool;
296
+ const ids = this.ids;
297
+ const density = pool.info(ids.density);
298
+ const b = { min: [...density.indexBBox.min], max: [...density.indexBBox.max] };
299
+ const old = this.indexBox;
300
+ const moved = b.min.some((v, a) => v !== old.min[a]) || b.max.some((v, a) => v !== old.max[a]);
301
+ this.indexBox = b;
302
+ this.texels = texelsOf(b);
303
+ this.boxToSource = boxToSourceOf(b, this.texels);
304
+ this.bbox = worldBox(b, density.indexToWorld);
305
+ const auxBox = (id) => (id === undefined ? null : { min: [...pool.info(id).indexBBox.min], max: [...pool.info(id).indexBBox.max] });
306
+ this.auxBoxes = { mask: auxBox(ids.mask), albedo: auxBox(Array.isArray(ids.albedo) ? ids.albedo[0] : ids.albedo), emission: auxBox(ids.emission) };
307
+ if (moved)
308
+ this.lodLevels = this.#lodLevelsOf(this.texels);
309
+ this.layoutUpdates++;
310
+ }
311
+ /**
312
+ * Content version: the newest `imageRevision` of the channel grids (K3.2a), so a `pool.replace` (a
313
+ * sequence frame) changes it and the 'frame' lighting caster signature (V44) draws the shadow grid
314
+ * again. Read through the pool's `revision` first (cheap when nothing changed).
315
+ */
316
+ get version() {
317
+ // G16a: a following source's version is the image revision its layout describes (it moves once the new image is
318
+ // resident and the boxes were re-read), so a VDBFrameVolume re-reads its box and the uniforms then.
319
+ if (this.followImage) {
320
+ this.syncLayout();
321
+ return this.#layoutRevision;
322
+ }
323
+ const pool = this.grids.pool;
324
+ if (typeof pool.revision !== "number")
325
+ return 0;
326
+ if (pool.revision !== this.#versionSeen.poolRevision) {
327
+ let value = 0;
328
+ for (const id of this.#poolIds) {
329
+ try {
330
+ value = Math.max(value, pool.info(id).imageRevision ?? 0);
331
+ }
332
+ catch {
333
+ // A removed grid: keep the others' revision.
334
+ }
335
+ }
336
+ this.#versionSeen = { poolRevision: pool.revision, value };
337
+ }
338
+ return this.#versionSeen.value;
339
+ }
340
+ refreshStats() {
341
+ if (this.#statsReadback)
342
+ return this.#statsReadback;
343
+ const pool = this.grids.pool;
344
+ // Cheap test first (once per render): the pool's revision moves on any change.
345
+ if (typeof pool.revision !== "number" || pool.revision === this.#statsPoolRevisionSeen || !pool.device || !pool.buffer)
346
+ return Promise.resolve(false);
347
+ let info;
348
+ try {
349
+ info = pool.info(this.ids.density);
350
+ }
351
+ catch {
352
+ return Promise.resolve(false); // removed: keep the last stats
353
+ }
354
+ const revision = info.imageRevision ?? -1;
355
+ if (revision === this.#statsRevision) {
356
+ this.#statsPoolRevisionSeen = pool.revision;
357
+ return Promise.resolve(false);
358
+ }
359
+ // Not written yet (the update that writes it is still to come): look again next time.
360
+ if (!info.resident || info.imageOffset === null || info.imageOffset === undefined || !info.imageBytes)
361
+ return Promise.resolve(false);
362
+ const { device, buffer } = pool;
363
+ const bytes = info.imageBytes;
364
+ const staging = device.createBuffer({ label: "vdbSparseSource stats readback", size: bytes, usage: 0x1 | 0x8 }); // MAP_READ | COPY_DST (no WebGPU globals in Node tests)
365
+ const encoder = device.createCommandEncoder({ label: "vdbSparseSource stats readback" });
366
+ encoder.copyBufferToBuffer(buffer, info.imageOffset, staging, 0, bytes);
367
+ device.queue.submit([encoder.finish()]);
368
+ const seen = pool.revision;
369
+ this.#statsReadback = staging
370
+ .mapAsync(0x1) // GPUMapMode.READ
371
+ .then(() => {
372
+ const image = new Uint32Array(staging.getMappedRange().slice(0));
373
+ this.stats = imageStats(image, this.normalize === "clamp01");
374
+ this.#statsRevision = revision;
375
+ this.#statsPoolRevisionSeen = seen;
376
+ this.statsUpdates++;
377
+ return true;
378
+ })
379
+ .catch(() => false)
380
+ .finally(() => {
381
+ staging.destroy();
382
+ this.#statsReadback = null;
383
+ });
384
+ return this.#statsReadback;
385
+ }
386
+ dispose() {
387
+ }
388
+ }
389
+ /**
390
+ * A sparse volume source over pool grids (see the file comment). `grids` must be a `VDBGridNode`
391
+ * made with profile `'march'` and helpers `['cellBoundTrilinear', 'hddaCellEnd']` (+ `'nodeAverage'`
392
+ * for that LOD). The source holds no GPU object (the pool's grid buffer is the pool's).
393
+ *
394
+ * @param grids A `VDBGridNode` with profile `march` and the helpers the LOD needs.
395
+ * @param ids The pool ids of the density grid and optional channels.
396
+ * @param options LOD, normalization, boxes, pyramid and sampling options.
397
+ */
398
+ export function vdbSparseSource(grids, ids, options = {}) {
399
+ if (!grids || typeof grids !== "object" || !("module" in grids))
400
+ throw bad("pass a VDBGridNode.");
401
+ if (!ids || !Number.isInteger(ids.density))
402
+ throw bad("ids.density must be a pool grid id.");
403
+ return new SparseSource(grids, ids, options);
404
+ }
405
+ //# sourceMappingURL=sparse-source.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sparse-source.js","sourceRoot":"","s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eUniforms /\n// createVolumeNodes (frameShaderChunks.js L729–763, L834–1028), whose sparse-grid port (the TSL half) was deleted in K6.11\n// (D35); this file is the handle the core's sparse source is made from.\n// Copyright (c) mjurczyk/openvdb contributors. Licensed under the MIT License (see THIRD_PARTY_NOTICES.md).\n// Divergences: DIVERGES.md (K3.2 rows), V23–V25, V145.\n\n/**\n * The sparse volume source (K3.2, R1 §4.2–4.3): a `VDBGridPool` grid behind the same seam as the\n * dense `.wvdb` source, so `VDBFrameVolume` renders NanoVDB grids.\n *\n * const grids = new VDBGridNode(renderer, pool, { profile: \"march\", helpers: [\"cellBoundTrilinear\", \"hddaCellEnd\", \"nodeAverage\", \"fastTrilinear\"] });\n * const source = vdbSparseSource(grids, { density: id }, { lod: \"coarse-pyramid\", images: { density: image } });\n * const volume = new VDBFrameVolume(source, { extinction: 100 }); // box: the grid's world box\n *\n * K6.8a / K6.11: the source is a handle (grids, ids, options, boxes, stats, the image-follow state). `VDBFrameRenderer`\n * reads it into the core's sparse source (`vdbSparseSource`), which builds its own pyramids and reads the grids itself.\n * The handle holds no GPU object. (Custom TSL materials sample a pooled grid through `VDBGridNode`; custom WGSL or compute\n * uses the core source's `wgsl()`.)\n *\n * Positions are his local unit box [-0.5, 0.5]³; uvw = local + 0.5 (+ offset, wrapped) maps onto the\n * channel grid's index cell box `[min − ½, max + ½]` (voxel centres at integers), so uvw\n * (i + 0.5) / N lands on voxel min + i as on a dense texel centre. The sample position is clamped to\n * `[min, max]` (his clamp-to-edge). Level 0 is the pool's trilinear sample; with the node helper\n * `'fastTrilinear'` (recommended, K3.2d) it is `vdbSampleFast` through one accessor per shader invocation\n * (`cacheAccessor`): the same values, 1.5–2× faster on the hardware GPU (docs/archive/handoffs/K3-2d.md). (The core's\n * sparse source reads these options.)\n *\n * LOD (`lod`, his `sampleExtinction(localPos, lod)` at lod ≥ 1; R1 §4.3):\n * - `'none'`: level 0 always (no prefilter; aliases when a froxel spans many voxels). lodLevels 0.\n * - `'coarse-pyramid'` (default, the K3.2 A/B pick): a dense r16f pyramid from L₀ = max(1, ⌈log2(maxTexels / pyramidMax)⌉):\n * the base is a box resample of the grid, the levels above it his box mip atlas. lod in (0, L₀)\n * blends level 0 toward L₀; lod ≥ L₀ samples the pyramid as his mip atlas. GPU bytes: ~2 B × (base\n * + atlas) texels. The core's sparse source builds it on the GPU from the pool grid (K3.2a: the core's\n * `vdbCreateBoxPyramid`, no CPU image needed) and rebuilds it when the grid's image changes\n * (`pool.replace`: a sequence frame). K6.11: the CPU build (`pyramidBuild: 'cpu'`, the three textures' static path) is\n * deleted; `@pmndrs/vdb/tools` `vdbBoxPyramid` stays the GPU build's CPU twin.\n * - `'node-average'`: no extra memory: trilinear over the node averages (`vdbNodeAverage`) at\n * level 3 (leaves, the exact 8³ box mean for fog leaves) and level 7 (lower nodes, the mean of\n * their active voxels); lod in (0, 3) blends level 0 → 3, (3, 7) blends 3 → 7. Needs stats.\n *\n * HDDA: `skipEmpty` lets a march jump samples that are provably 0 (`VDBFrameVolume` `hdda`, default\n * off since D30 / D31: it slowed the shadow march on Apple GPUs; the image is the same either way).\n *\n * Following the image (`followImage`, G16a): the index boxes, world box and pyramid are fixed when the source is\n * made unless it follows the grids' images. Then a `pool.replace` that changes a channel grid's box (a coarse-first\n * swap: the preview, then the full grid in the same id) is re-read from `pool.info` once the new image is resident:\n * the new layout, the LOD range and a new `version`, which a `VDBFrameVolume` follows with its box. No shader is rebuilt.\n *\n * Mask, albedo and emission grids (optional, scalar; albedo may be three grids for RGB) are read at\n * level 0 only. One VDB module per shader: every grid goes through the one `VDBGridNode`.\n */\n\nimport { VDBError } from \"../core/errors.js\";\nimport type { VDBVolumeChannels } from \"../core/source/types.js\";\nimport { vdbBoxPyramidLayout } from \"../tools/frame/pyramid-layout.js\";\nimport { leafVoxels, treeNodes } from \"../tools/cpu/march.js\";\nimport type { VDBGridNode } from \"./grid-node.js\";\nimport type { VDBVolumeSourceInfo } from \"../core/source/types.js\";\n\ntype Vec3 = [number, number, number];\n\n/** The LOD strategies of the sparse source (R1 §4.3); see the file comment. */\nexport type VDBSparseLod = \"none\" | \"coarse-pyramid\" | \"node-average\";\n\n/** The pool grid ids of the channels. `albedo`: one grey grid or three (RGB). */\nexport interface VDBSparseSourceGrids {\n /** Pool id of the density grid. */\n density: number;\n /** Pool id of an optional mask grid (multiplies the density). */\n mask?: number;\n /** Pool id of one grey albedo grid, or three ids for RGB. */\n albedo?: number | readonly [number, number, number];\n /** Pool id of an optional emission (temperature) grid. */\n emission?: number;\n}\n\n/** Inclusive voxel index box. */\nexport interface VDBIndexBox {\n /** Smallest voxel index (inclusive). */\n min: Vec3;\n /** Largest voxel index (inclusive). */\n max: Vec3;\n}\n\n/** Options of {@link vdbSparseSource}. */\nexport interface VDBSparseSourceOptions {\n /**\n * LOD strategy. Default `'coarse-pyramid'`, the K3.2 A/B's pick (closest to his mips, low flicker, cheap to\n * sample; needs `images.density`); see docs/archive/handoffs/K3-2.md.\n */\n lod?: VDBSparseLod;\n /** `'coarse-pyramid'`: base level texels on the longest side at most (default 128). */\n pyramidMax?: number;\n /** `'none'` (default): raw floats. `'clamp01'`: clamp each density sample to [0, 1] (his 8-bit range; parity A/B). */\n normalize?: \"none\" | \"clamp01\";\n /** CPU copies of the grid images: the density stats read `density`. */\n images?: { density?: Uint32Array };\n /**\n * Density stats (`normalizeDensity` divides by `meanNonZero`). Default: computed from `images.density`.\n * Either way they describe the image at creation; after the density grid's image changes (`pool.replace`,\n * its `imageRevision`) the source reads the new image back from the pool and recomputes them (K3.2e; see\n * `statsUpdates`).\n */\n stats?: { meanNonZero: number; max: number; activeVoxels: number };\n /** Density index box the unit box covers (default: the grid's index bbox). Aux grids use their own. */\n indexBox?: VDBIndexBox;\n /**\n * K3.6: index boxes the unit box covers in the aux grids (default: each grid's own index bbox). Grids converted\n * from one dense `.wvdb` level (`wvdbDenseToNvdb`) share the texture's box (`textureIndexBox`); pass it so a\n * sparse emission or mask channel lines up with the density (its active bbox is usually smaller).\n */\n auxIndexBoxes?: Partial<Record<\"mask\" | \"albedo\" | \"emission\", VDBIndexBox>>;\n /** World box (default: the density cell box through the grid's transform, as an AABB). */\n bbox?: [Vec3, Vec3];\n /**\n * K3.2d: level-0 samples through `vdbSampleFast` (the 8 trilinear taps as lower-node child lookups, no\n * tree walk per tap; bit-identical to `vdbSample`). Needs the `VDBGridNode` helper `'fastTrilinear'`.\n * Default: on when the node has the helper.\n */\n fastTrilinear?: boolean;\n /**\n * K3.2d: keep one accessor per shader invocation (a WGSL `var<private>`) across the samples of a march\n * instead of a fresh one per sample, so consecutive samples reuse its cached leaf/lower/upper nodes. The\n * values are the same either way. Default true (the K3.2d hardware A/B: with `fastTrilinear`, whose taps\n * start from the cached lower node, 10–25% off the source passes; alone it changes little).\n */\n cacheAccessor?: boolean;\n /**\n * G16a: follow the grids' images. When a channel grid's `imageRevision` moves (a `pool.replace`, e.g. a\n * `vdbStreamCoarseFirst` swap from the preview to the full grid) and every channel grid is resident again, the\n * source re-reads its index boxes, world box and transform from `pool.info`, rebuilds the coarse pyramid at the\n * new size and bumps `version` (a `VDBFrameVolume` whose box is the source's follows it). Boxes, sizes and LOD\n * levels are uniforms in this mode, so nothing recompiles; give the `VDBGridNode` every grid type the images will\n * have (`types`, e.g. `VDBCoarseFirstEvent.types`): a new image of a type the node does not compile throws\n * `VDB_TYPE_NOT_COMPILED` when the source re-reads it (it would read 0). Default false: the boxes are fixed when the\n * source is made. Not with `indexBox`, `auxIndexBoxes` or `bbox`.\n */\n followImage?: boolean;\n}\n\n/**\n * Internal options of {@link vdbSparseSource} (`three/internal.ts`): K3.2f, the core source's brick cache (level-0\n * density from a dense atlas of the touched 8³ blocks; core `VDBSparseSourceInternalOptions`). Opt-in until K6.T times it.\n */\nexport interface VDBThreeSparseSourceInternalOptions extends VDBSparseSourceOptions {\n /** `'off'` (default), `'f32'` (bit-identical to the tree) or `'f16'` (one filtered fetch, bounded). */\n brickCache?: \"off\" | \"f32\" | \"f16\";\n /** K3.2f-e: the core source's `brickKernels`, `brickMarkStats`, `brickCapacity` and `brickBudget` (with `brickCache`). */\n brickKernels?: \"all\" | \"gather-marks\" | \"gather-only\";\n brickMarkStats?: boolean;\n brickCapacity?: number;\n brickBudget?: number;\n}\n\n/** K3.2f-e: the brick cache options a three source passes to its core source (absent ones keep the core defaults). */\nexport interface VDBThreeBrickOptions {\n readonly brickKernels?: \"all\" | \"gather-marks\" | \"gather-only\";\n readonly brickMarkStats?: boolean;\n readonly brickCapacity?: number;\n readonly brickBudget?: number;\n}\n\n/** What the source needs from a pool: `info` and the ids' grids (a `VDBGridPool`). */\ninterface PoolInfoLike {\n info(id: number): { indexBBox: { min: Vec3; max: Vec3 }; indexToWorld: Float64Array; hasStats: boolean; capacity: number; type: string; imageRevision?: number; resident?: boolean };\n}\n\n/** The sparse source in three. */\nexport interface VDBThreeSparseSource extends VDBVolumeSourceInfo {\n /** Always `\"sparse\"`. */\n readonly kind: \"sparse\";\n /** World box of the volume (`[min, max]`), the default `VDBFrameVolume` box. */\n readonly bbox: [[number, number, number], [number, number, number]];\n /** The grid node the source reads through. */\n readonly grids: VDBGridNode;\n /** The pool ids of the channels. */\n readonly ids: Readonly<VDBSparseSourceGrids>;\n /** The LOD strategy in use. */\n readonly lod: VDBSparseLod;\n /** Density normalization: `'clamp01'` clamps to [0, 1], `'none'` leaves it. */\n readonly normalize: \"none\" | \"clamp01\";\n /** The density index box the unit box covers. */\n readonly indexBox: VDBIndexBox;\n /** K3.2d: level 0 through `vdbSampleFast` (see the option). */\n readonly fastTrilinear: boolean;\n /** K3.2d: one accessor per invocation across samples (see the option). */\n readonly cacheAccessor: boolean;\n /** G16a: the boxes follow the grids' images (see the option). */\n readonly followImage: boolean;\n /** G16a: times the boxes (and the pyramid, if its size changed) were re-read after an image change. */\n readonly layoutUpdates: number;\n /**\n * GPU bytes of the channel grids' pool ranges. The LOD pyramid is the core source's (demo 15:\n * `frameRenderer.coreVolumeOf(volume).slot.source.gpuBytes`).\n */\n readonly gpuBytes: { readonly pool: number };\n /** Density stats (`normalizeDensity`'s `meanNonZero`): of the density image at creation, then of the latest one read back (K3.2e). */\n readonly stats: { readonly meanNonZero: number; readonly max: number; readonly activeVoxels: number };\n /** Times the stats were recomputed after an image change (K3.2e). */\n readonly statsUpdates: number;\n /**\n * K3.2e: if the density grid's image changed since the stats were computed and it is resident, reads it\n * back from the pool (own encoder, submitted) and recomputes the stats (tools' twin of the CPU path);\n * resolves to whether it did. K6.11: nothing calls it for you (the TSL uniforms that did are deleted); `VDBFrameRenderer`\n * copies a changed `stats` into its core slot, which otherwise re-reads the mean itself a frame or two later. Call it\n * after `pool.update` was submitted, as `grids.update()`; await it when the first frame needs the new mean.\n */\n refreshStats(): Promise<boolean>;\n /** Drops the listeners. */\n dispose(): void;\n}\n\nconst bad = (message: string) => new VDBError(\"VDB_BAD_OPTION\", `vdbSparseSource: ${message}`);\n\n/** The non-zero density stats of an image (all leaf voxels, active or not, and active tiles). */\nfunction imageStats(image: Uint32Array, clamp01: boolean): { meanNonZero: number; max: number; activeVoxels: number } {\n let sum = 0;\n let count = 0;\n let maxValue = 0;\n const add = (v: number, n: number) => {\n const x = clamp01 ? Math.min(Math.max(v, 0), 1) : v;\n if (x !== 0) {\n sum += x * n;\n count += n;\n maxValue = Math.max(maxValue, x);\n }\n };\n for (const node of treeNodes(image)) {\n for (const t of node.activeTiles) add(t.value, t.dim ** 3);\n if (node.level !== 0) continue;\n const { values } = leafVoxels(image, node.address);\n for (let n = 0; n < 512; n++) add(values[n]!, 1);\n }\n return { meanNonZero: count > 0 ? sum / count : 0, max: maxValue, activeVoxels: count };\n}\n\n/** World AABB of an index cell box through a 3x4 row-major affine. */\nfunction worldBox(box: VDBIndexBox, m: Float64Array): [Vec3, Vec3] {\n const lo: Vec3 = [Infinity, Infinity, Infinity];\n const hi: Vec3 = [-Infinity, -Infinity, -Infinity];\n for (let c = 0; c < 8; c++) {\n const p = [c & 1 ? box.max[0] + 0.5 : box.min[0] - 0.5, c & 2 ? box.max[1] + 0.5 : box.min[1] - 0.5, c & 4 ? box.max[2] + 0.5 : box.min[2] - 0.5];\n for (let r = 0; r < 3; r++) {\n const v = m[r * 4]! * p[0]! + m[r * 4 + 1]! * p[1]! + m[r * 4 + 2]! * p[2]! + m[r * 4 + 3]!;\n lo[r] = Math.min(lo[r]!, v);\n hi[r] = Math.max(hi[r]!, v);\n }\n }\n return [lo, hi];\n}\n\n/** Local unit box → sample index space: p = min − ½ + (local + ½)·size (column-major). */\nfunction boxToSourceOf(b: VDBIndexBox, texels: Vec3): Float32Array {\n const [sx, sy, sz] = texels;\n return new Float32Array([sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, sz, 0, b.min[0] - 0.5 + 0.5 * sx, b.min[1] - 0.5 + 0.5 * sy, b.min[2] - 0.5 + 0.5 * sz, 1]);\n}\n\nconst texelsOf = (b: VDBIndexBox): Vec3 => [b.max[0] - b.min[0] + 1, b.max[1] - b.min[1] + 1, b.max[2] - b.min[2] + 1];\n\n/**\n * The handle (K6.8a): grids, ids, options, boxes, stats and the image-follow state. The frame renderer reads these into\n * the core's sparse source.\n */\nclass SparseSource implements VDBThreeSparseSource {\n readonly kind = \"sparse\" as const;\n readonly grids: VDBGridNode;\n readonly ids: Readonly<VDBSparseSourceGrids>;\n readonly lod: VDBSparseLod;\n readonly normalize: \"none\" | \"clamp01\";\n readonly channels: VDBVolumeChannels;\n // G16a: the layout fields below are re-read after an image change when `followImage` is on.\n indexBox: VDBIndexBox;\n auxBoxes: Record<\"mask\" | \"albedo\" | \"emission\", VDBIndexBox | null>;\n texels: [number, number, number];\n lodLevels: number;\n stats: { meanNonZero: number; max: number; activeVoxels: number };\n statsUpdates = 0;\n boxToSource: Float32Array;\n bbox: [Vec3, Vec3];\n readonly fastTrilinear: boolean;\n readonly cacheAccessor: boolean;\n readonly followImage: boolean;\n readonly pyramidOptions: { readonly pyramidMax?: number };\n /** K3.2f (internal): the core source's brick cache. */\n readonly brickCache: \"off\" | \"f32\" | \"f16\";\n /** K3.2f-e (internal): the core source's other brick options (validated by the core source). */\n readonly brickOptions: VDBThreeBrickOptions;\n layoutUpdates = 0;\n /** G16a: the newest channel imageRevision the layout describes, the pool revision last checked. */\n #layoutRevision = -1;\n #layoutPoolRevision = -1;\n readonly #poolIds: number[];\n #versionSeen = { poolRevision: -1, value: 0 };\n /** K3.2e: the density imageRevision the stats describe, the pool revision last checked, and a readback in flight. */\n #statsRevision = -1;\n #statsPoolRevisionSeen = -1;\n #statsReadback: Promise<boolean> | null = null;\n\n constructor(grids: VDBGridNode, ids: VDBSparseSourceGrids, o: VDBSparseSourceOptions) {\n const pool = grids.pool as unknown as Partial<PoolInfoLike>;\n if (typeof pool.info !== \"function\") throw bad(\"the VDBGridNode's pool has no info(); pass a VDBGridPool.\");\n const info = (id: number) => (pool as PoolInfoLike).info(id);\n const lod = o.lod ?? \"coarse-pyramid\";\n if (lod !== \"none\" && lod !== \"coarse-pyramid\" && lod !== \"node-average\") throw bad(`unknown lod ${JSON.stringify(lod)}; use 'none', 'coarse-pyramid' or 'node-average'.`);\n const normalize = o.normalize ?? \"none\";\n if (normalize !== \"none\" && normalize !== \"clamp01\") throw bad(`unknown normalize ${JSON.stringify(normalize)}; use 'none' or 'clamp01'.`);\n const helpers = new Set<string>(grids.options.helpers ?? []);\n if (grids.options.profile !== \"march\" || !helpers.has(\"cellBoundTrilinear\") || !helpers.has(\"hddaCellEnd\") || (lod === \"node-average\" && !helpers.has(\"nodeAverage\"))) {\n throw bad(\n `make the VDBGridNode with profile 'march' and helpers ['cellBoundTrilinear', 'hddaCellEnd'${lod === \"node-average\" ? \", 'nodeAverage'\" : \"\"}] ` +\n `(got profile '${grids.options.profile}', helpers [${[...helpers].join(\", \")}]).`,\n );\n }\n const fastTrilinear = o.fastTrilinear ?? helpers.has(\"fastTrilinear\");\n if (fastTrilinear && !helpers.has(\"fastTrilinear\")) throw bad(\"fastTrilinear needs the VDBGridNode helper 'fastTrilinear' (add it to helpers), or pass fastTrilinear: false.\");\n if (fastTrilinear && grids.options.sampler === \"nearest\") throw bad(\"fastTrilinear needs the VDBGridNode's sampler 'trilinear'.\");\n this.fastTrilinear = fastTrilinear;\n this.cacheAccessor = o.cacheAccessor ?? true;\n const brickCache = (o as VDBThreeSparseSourceInternalOptions).brickCache ?? \"off\";\n if (brickCache !== \"off\" && brickCache !== \"f32\" && brickCache !== \"f16\") throw bad(`brickCache must be 'off', 'f32' or 'f16', got ${JSON.stringify(brickCache)}.`);\n this.brickCache = brickCache;\n const io = o as VDBThreeSparseSourceInternalOptions;\n this.brickOptions = Object.freeze({\n ...(io.brickKernels !== undefined ? { brickKernels: io.brickKernels } : {}),\n ...(io.brickMarkStats !== undefined ? { brickMarkStats: io.brickMarkStats } : {}),\n ...(io.brickCapacity !== undefined ? { brickCapacity: io.brickCapacity } : {}),\n ...(io.brickBudget !== undefined ? { brickBudget: io.brickBudget } : {}),\n });\n const followImage = o.followImage ?? false;\n if (typeof followImage !== \"boolean\") throw bad(\"followImage must be a boolean.\");\n if (followImage) {\n const fixed = ([\"indexBox\", \"auxIndexBoxes\", \"bbox\"] as const).filter((k) => o[k] !== undefined);\n if (fixed.length) throw bad(`followImage re-reads every box from the pool; drop ${fixed.join(\", \")} (fixed boxes).`);\n }\n this.followImage = followImage;\n const density = info(ids.density);\n if (lod === \"node-average\" && !density.hasStats) throw bad(\"lod 'node-average' reads node statistics; this grid has none (rebuild it with stats).\");\n this.grids = grids;\n const channelIds = [ids.density, ids.mask, ids.emission, ...(Array.isArray(ids.albedo) ? ids.albedo : [ids.albedo])].filter((v): v is number => v !== undefined);\n this.checkTypes(\n channelIds.map((id) => ({ id, type: info(id).type })),\n \"a channel grid\",\n );\n this.ids = Object.freeze({ ...ids, ...(Array.isArray(ids.albedo) ? { albedo: [...ids.albedo] as unknown as [number, number, number] } : {}) });\n this.lod = lod;\n this.normalize = normalize;\n this.indexBox = o.indexBox ? { min: [...o.indexBox.min], max: [...o.indexBox.max] } : { min: [...density.indexBBox.min], max: [...density.indexBBox.max] };\n const albedoId = Array.isArray(ids.albedo) ? ids.albedo[0] : (ids.albedo as number | undefined);\n const box = (id: number | undefined, given?: VDBIndexBox) =>\n id === undefined ? null : given ? { min: [...given.min] as Vec3, max: [...given.max] as Vec3 } : { min: [...info(id).indexBBox.min] as Vec3, max: [...info(id).indexBBox.max] as Vec3 };\n const aux = o.auxIndexBoxes ?? {};\n this.auxBoxes = { mask: box(ids.mask, aux.mask), albedo: box(albedoId, aux.albedo), emission: box(ids.emission, aux.emission) };\n this.channels = { mask: ids.mask !== undefined, albedo: ids.albedo !== undefined, emission: ids.emission !== undefined };\n const b = this.indexBox;\n this.texels = texelsOf(b);\n if (this.texels.some((t) => !(t > 0))) throw bad(\"the density index box is empty.\");\n const image = o.images?.density;\n if (o.stats) this.stats = { ...o.stats };\n else if (image) this.stats = imageStats(image, normalize === \"clamp01\");\n else throw bad(\"pass images.density (the CPU image, for the density stats) or stats.\");\n this.#statsRevision = (density as { imageRevision?: number }).imageRevision ?? -1;\n this.boxToSource = boxToSourceOf(b, this.texels);\n this.bbox = o.bbox ? [[...o.bbox[0]], [...o.bbox[1]]] : worldBox(b, density.indexToWorld);\n\n this.pyramidOptions = o.pyramidMax !== undefined ? { pyramidMax: o.pyramidMax } : {};\n this.lodLevels = this.#lodLevelsOf(this.texels);\n this.#poolIds = [...new Set(channelIds)];\n this.#layoutRevision = this.#poolIds.reduce((r, id) => Math.max(r, info(id).imageRevision ?? 0), 0);\n }\n\n /** The LOD range: 0 (`'none'`), 7 (`'node-average'`), the pyramid layout's levels (`'coarse-pyramid'`). */\n #lodLevelsOf(texels: Vec3): number {\n if (this.lod === \"none\") return 0;\n if (this.lod === \"node-average\") return 7;\n const { pyramidMax } = this.pyramidOptions;\n return vdbBoxPyramidLayout(texels, pyramidMax !== undefined ? { pyramidMax } : {}).lodLevels;\n }\n\n /** GPU bytes of the channel grids' pool ranges. */\n get gpuBytes(): { pool: number } {\n const pool = this.grids.pool as unknown as PoolInfoLike;\n let bytes = 0;\n for (const id of this.#poolIds) {\n try {\n bytes += pool.info(id).capacity;\n } catch {\n // A removed grid holds no pool range.\n }\n }\n return { pool: bytes };\n }\n\n /**\n * G16a (`followImage`): re-reads the layout when a channel grid's image changed and every channel grid is resident\n * again (the update that writes the new image has run: the GPU must not read it through the old boxes, nor the\n * old image through the new ones). Cheap when the pool's revision did not move; called from `version` (a\n * `VDBFrameVolume` asks once per frame, before it places its box) and from the render updates.\n */\n syncLayout(): boolean {\n if (!this.followImage) return false;\n const pool = this.grids.pool as unknown as { revision?: number } & PoolInfoLike;\n if (typeof pool.revision !== \"number\" || pool.revision === this.#layoutPoolRevision) return false;\n let revision = 0;\n let resident = true;\n const infos: { id: number; type: string }[] = [];\n for (const id of this.#poolIds) {\n let i: ReturnType<PoolInfoLike[\"info\"]>;\n try {\n i = pool.info(id);\n } catch {\n return false; // a removed grid: keep the last layout\n }\n revision = Math.max(revision, i.imageRevision ?? 0);\n if (i.resident === false) resident = false;\n infos.push({ id, type: i.type });\n }\n if (revision === this.#layoutRevision) {\n this.#layoutPoolRevision = pool.revision;\n return false;\n }\n if (!resident) return false; // look again once the update has written it\n // A new image of a type the module does not decode would read 0 through the new boxes, silently: say so instead\n // (every call until the source is remade over a node that compiles it).\n this.checkTypes(infos, \"a channel grid's new image\");\n this.#relayout();\n this.#layoutRevision = revision;\n this.#layoutPoolRevision = pool.revision;\n return true;\n }\n\n /**\n * Throws `VDB_TYPE_NOT_COMPILED` when a channel grid's type is not among the `VDBGridNode`'s compiled `types` (those\n * grids read 0). A node stand-in without `options.types` is not checked.\n */\n private checkTypes(infos: readonly { id: number; type: string }[], what: string): void {\n const compiled = (this.grids.options as { types?: readonly string[] }).types;\n if (!compiled) return;\n const missing = infos.filter((i) => !compiled.includes(i.type));\n if (missing.length === 0) return;\n throw new VDBError(\n \"VDB_TYPE_NOT_COMPILED\",\n `vdbSparseSource: ${what} is ${missing.map((m) => `grid ${m.id}: ${m.type}`).join(\", \")}, but the VDBGridNode compiles only ` +\n `${compiled.join(\", \")}; it would read 0. Make the VDBGridNode with types that include every type the images will have ` +\n `(a coarse-first stream lists them in VDBCoarseFirstEvent.types: types: event.types), then make the source over it.`,\n );\n }\n\n #relayout(): void {\n const pool = this.grids.pool as unknown as PoolInfoLike;\n const ids = this.ids;\n const density = pool.info(ids.density);\n const b: VDBIndexBox = { min: [...density.indexBBox.min], max: [...density.indexBBox.max] };\n const old = this.indexBox;\n const moved = b.min.some((v, a) => v !== old.min[a]) || b.max.some((v, a) => v !== old.max[a]);\n this.indexBox = b;\n this.texels = texelsOf(b);\n this.boxToSource = boxToSourceOf(b, this.texels);\n this.bbox = worldBox(b, density.indexToWorld);\n const auxBox = (id: number | undefined): VDBIndexBox | null => (id === undefined ? null : { min: [...pool.info(id).indexBBox.min] as Vec3, max: [...pool.info(id).indexBBox.max] as Vec3 });\n this.auxBoxes = { mask: auxBox(ids.mask), albedo: auxBox(Array.isArray(ids.albedo) ? ids.albedo[0] : (ids.albedo as number | undefined)), emission: auxBox(ids.emission) };\n if (moved) this.lodLevels = this.#lodLevelsOf(this.texels);\n this.layoutUpdates++;\n }\n\n /**\n * Content version: the newest `imageRevision` of the channel grids (K3.2a), so a `pool.replace` (a\n * sequence frame) changes it and the 'frame' lighting caster signature (V44) draws the shadow grid\n * again. Read through the pool's `revision` first (cheap when nothing changed).\n */\n get version(): number {\n // G16a: a following source's version is the image revision its layout describes (it moves once the new image is\n // resident and the boxes were re-read), so a VDBFrameVolume re-reads its box and the uniforms then.\n if (this.followImage) {\n this.syncLayout();\n return this.#layoutRevision;\n }\n const pool = this.grids.pool as unknown as { revision?: number; info(id: number): { imageRevision?: number } };\n if (typeof pool.revision !== \"number\") return 0;\n if (pool.revision !== this.#versionSeen.poolRevision) {\n let value = 0;\n for (const id of this.#poolIds) {\n try {\n value = Math.max(value, pool.info(id).imageRevision ?? 0);\n } catch {\n // A removed grid: keep the others' revision.\n }\n }\n this.#versionSeen = { poolRevision: pool.revision, value };\n }\n return this.#versionSeen.value;\n }\n\n refreshStats(): Promise<boolean> {\n if (this.#statsReadback) return this.#statsReadback;\n const pool = this.grids.pool as unknown as {\n revision?: number;\n device?: GPUDevice;\n buffer?: GPUBuffer;\n info(id: number): { imageRevision?: number; resident?: boolean; imageOffset?: number | null; imageBytes?: number };\n };\n // Cheap test first (once per render): the pool's revision moves on any change.\n if (typeof pool.revision !== \"number\" || pool.revision === this.#statsPoolRevisionSeen || !pool.device || !pool.buffer) return Promise.resolve(false);\n let info: ReturnType<typeof pool.info>;\n try {\n info = pool.info(this.ids.density);\n } catch {\n return Promise.resolve(false); // removed: keep the last stats\n }\n const revision = info.imageRevision ?? -1;\n if (revision === this.#statsRevision) {\n this.#statsPoolRevisionSeen = pool.revision;\n return Promise.resolve(false);\n }\n // Not written yet (the update that writes it is still to come): look again next time.\n if (!info.resident || info.imageOffset === null || info.imageOffset === undefined || !info.imageBytes) return Promise.resolve(false);\n const { device, buffer } = pool;\n const bytes = info.imageBytes;\n const staging = device.createBuffer({ label: \"vdbSparseSource stats readback\", size: bytes, usage: 0x1 | 0x8 }); // MAP_READ | COPY_DST (no WebGPU globals in Node tests)\n const encoder = device.createCommandEncoder({ label: \"vdbSparseSource stats readback\" });\n encoder.copyBufferToBuffer(buffer, info.imageOffset, staging, 0, bytes);\n device.queue.submit([encoder.finish()]);\n const seen = pool.revision;\n this.#statsReadback = staging\n .mapAsync(0x1) // GPUMapMode.READ\n .then(() => {\n const image = new Uint32Array(staging.getMappedRange().slice(0));\n this.stats = imageStats(image, this.normalize === \"clamp01\");\n this.#statsRevision = revision;\n this.#statsPoolRevisionSeen = seen;\n this.statsUpdates++;\n return true;\n })\n .catch(() => false)\n .finally(() => {\n staging.destroy();\n this.#statsReadback = null;\n });\n return this.#statsReadback;\n }\n\n dispose(): void {\n }\n}\n\n/**\n * A sparse volume source over pool grids (see the file comment). `grids` must be a `VDBGridNode`\n * made with profile `'march'` and helpers `['cellBoundTrilinear', 'hddaCellEnd']` (+ `'nodeAverage'`\n * for that LOD). The source holds no GPU object (the pool's grid buffer is the pool's).\n *\n * @param grids A `VDBGridNode` with profile `march` and the helpers the LOD needs.\n * @param ids The pool ids of the density grid and optional channels.\n * @param options LOD, normalization, boxes, pyramid and sampling options.\n */\nexport function vdbSparseSource(grids: VDBGridNode, ids: VDBSparseSourceGrids, options: VDBSparseSourceOptions = {}): VDBThreeSparseSource {\n if (!grids || typeof grids !== \"object\" || !(\"module\" in grids)) throw bad(\"pass a VDBGridNode.\");\n if (!ids || !Number.isInteger(ids.density)) throw bad(\"ids.density must be a pool grid id.\");\n return new SparseSource(grids, ids, options);\n}\n"]}
@@ -0,0 +1,22 @@
1
+ import type { VDBVolumeSourceInfo } from "../core/source/types.js";
2
+ import type { WvdbDenseVolume } from "../tools/wvdb/dense.js";
3
+ import type { VDBThreeSparseSource } from "./sparse-source.js";
4
+ /** A dense source as a handle (the descriptive part of `VDBVolumeSource`; no raw bindings). */
5
+ export interface VDBThreeDenseSource extends VDBVolumeSourceInfo {
6
+ /** Always `"dense"`. */
7
+ readonly kind: "dense";
8
+ /** The `.wvdb` volume currently set (`VDBFrameVolume`: the core frame renderer uploads it into its own textures). */
9
+ readonly volume: WvdbDenseVolume;
10
+ /**
11
+ * Swap in another LOD or sequence frame. New sizes bump `version`, and so does a frame with another `.wvdb` box
12
+ * (a `VDBFrameVolume` follows by itself, its box too unless it was given a `bbox`). A channel the source lacks is
13
+ * ignored (warned once). The density's mip atlas must stay if the source has one.
14
+ */
15
+ replace(volume: WvdbDenseVolume): void;
16
+ /** Releases the handle (it holds no GPU object). */
17
+ dispose(): void;
18
+ }
19
+ /** A volume source `VDBFrameVolume` reads: a dense `.wvdb` volume or a pool grid. */
20
+ export type VDBThreeVolumeSource = VDBThreeDenseSource | VDBThreeSparseSource;
21
+ /** A dense `.wvdb` volume (`wvdbDenseVolume`, `@pmndrs/vdb/tools`) as a handle for `VDBFrameVolume`. */
22
+ export declare function vdbDenseTextures(volume: WvdbDenseVolume): VDBThreeDenseSource;