@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,361 @@
1
+ /**
2
+ * bake.ts — resample sparse grids (a parsed `.vdb`, or a NanoVDB grid image
3
+ * through the CPU oracle) to dense levels and write a `.wvdb`.
4
+ *
5
+ * Portions derived from mjurczyk/openvdb (MIT), commit 75e7345:
6
+ * `src/wvdb/bake.js` (getWVDBBox, getFinestDimensions, forEachTexel,
7
+ * sampleScalarGrid, the level-set band limit, getBakedGrids and
8
+ * encodePointGrid: point data grids become points grids in file order, G14b)
9
+ * and `src/wvdb/cli.js` (the `source` member). His sampling is reproduced, including its arithmetic order:
10
+ * - one shared world box for all grids: the union of the grids' active-voxel
11
+ * index boxes (voxel centres, so `max` is the last voxel, not one past it)
12
+ * mapped to world space, unless `bbox` is given;
13
+ * - the finest LOD has `resolution` voxels on the longest box side, the other
14
+ * sides `max(1, round(side * resolution / longest))` (§3.2.1);
15
+ * - **point sampling, no prefilter** (§3.2.2): world position of voxel centre
16
+ * `min + ((i + 0.5) / X) * size`, mapped to index space with the inverse
17
+ * map, rounded with `Math.round` (halves toward +infinity) and read with
18
+ * the grid's own value lookup (inactive values included). A source much
19
+ * finer than the target resolution aliases; that is his behaviour and the
20
+ * default here (`sampling: 'nearest'`).
21
+ *
22
+ * Options beyond his CLI (K4.13):
23
+ * - `sampling: 'box'` prefilters: each texel is the area-weighted mean of the
24
+ * source voxels its cell covers, on the same lattice (`vdbResampleDense`, the
25
+ * K4.4 `vdbResampleGrid` box filter). Mass is conserved and thin features fade
26
+ * instead of flickering in and out;
27
+ * - `levelSetSampler: 'surface-mean'` samples level sets with his CLI's
28
+ * `sampleLevelSet` (`level-set.ts`), which reproduces his level-set files.
29
+ *
30
+ * Differences from his CLI (also in docs/archive/handoffs/K4-3.md):
31
+ * - by default (`levelSetSampler: 'spec'`) level sets are point-sampled and
32
+ * then encoded by the §8 rule (active: clamp to `±(b - 2b/maxCode)`;
33
+ * inactive: `±b` by sign). His CLI uses `sampleLevelSet` (a surface-aware
34
+ * mean) instead, so level-set bytes differ (DIVERGES V17);
35
+ * - `dimensions` can override the finest LOD size (his pre-0.11 bakes used
36
+ * `resolution`³ for every box, e.g. the committed `smoke.wvdb` and
37
+ * `bunny_cloud.wvdb`; this reproduces them).
38
+ */
39
+ import { VDBToolsError, VDBUnsupportedError } from "../errors.js";
40
+ import { vdbReadValueCpu } from "../cpu/read-value.js";
41
+ import { vdbResampleDense } from "../nanovdb/resample.js";
42
+ import { gridTypeConstantsForId } from "../cpu/stride-tables.js";
43
+ import { GRID_NAME_MAX, GRID_OFF_GRID_CLASS, GRID_OFF_GRID_NAME, GRID_OFF_GRID_TYPE, GRID_OFF_MAP, GRID_SIZE, MAP_OFF_INVMATD, MAP_OFF_MATD, MAP_OFF_VECD, ROOT_OFF_BBOX_MAX, ROOT_OFF_BBOX_MIN, TREE_OFF_NODE_OFFSET_ROOT, } from "../nanovdb/bytes.js";
44
+ import { parseVdb } from "../vdb/parse.js";
45
+ import { vdbPointRenderData } from "../vdb/point-render-data.js";
46
+ import { sampleWvdbLevelSetSurfaceMean } from "./level-set.js";
47
+ import { sha256Hex } from "./sha256.js";
48
+ import { writeWvdb, } from "./write.js";
49
+ function unionBox(boxes) {
50
+ if (!boxes.length)
51
+ return null;
52
+ const min = [...boxes[0][0]];
53
+ const max = [...boxes[0][1]];
54
+ for (const [lo, hi] of boxes.slice(1)) {
55
+ for (let a = 0; a < 3; a++) {
56
+ min[a] = Math.min(min[a], lo[a]);
57
+ max[a] = Math.max(max[a], hi[a]);
58
+ }
59
+ }
60
+ return [min, max];
61
+ }
62
+ /** §3.2.1, his `getFinestDimensions`. */
63
+ export function wvdbFinestDimensions(bbox, resolution) {
64
+ const size = bbox ? [0, 1, 2].map((a) => bbox[1][a] - bbox[0][a]) : [0, 0, 0];
65
+ const longest = Math.max(...size);
66
+ if (!(longest > 0))
67
+ return [resolution, resolution, resolution];
68
+ return size.map((side) => Math.max(1, Math.round((side * resolution) / longest)));
69
+ }
70
+ /** Point-samples one source over the box (his `forEachTexel` + `sampleScalarGrid`). */
71
+ export function sampleWvdbDense(source, bbox, dimensions, bits = 8) {
72
+ const [w, h, d] = dimensions;
73
+ const values = new Float32Array(w * h * d);
74
+ const background = source.background;
75
+ if (!source.bbox || !bbox)
76
+ return values.fill(background);
77
+ const min = bbox[0];
78
+ const size = [0, 1, 2].map((a) => bbox[1][a] - min[a]);
79
+ const isLevelSet = source.class === "level set";
80
+ const band = background - (2 * background) / ((1 << bits) - 1);
81
+ const world = [0, 0, 0];
82
+ let o = 0;
83
+ for (let z = 0; z < d; z++) {
84
+ world[2] = ((z + 0.5) / d) * size[2] + min[2];
85
+ for (let y = 0; y < h; y++) {
86
+ world[1] = ((y + 0.5) / h) * size[1] + min[1];
87
+ for (let x = 0; x < w; x++) {
88
+ world[0] = ((x + 0.5) / w) * size[0] + min[0];
89
+ const { value, active } = source.sample(world);
90
+ let v = Number.isFinite(value) ? value : background;
91
+ if (isLevelSet)
92
+ v = active ? Math.min(Math.max(v, -band), band) : v < 0 ? -background : background;
93
+ values[o++] = v;
94
+ }
95
+ }
96
+ }
97
+ return values;
98
+ }
99
+ /**
100
+ * Box-filters one source over the box (`sampling: 'box'`): `vdbResampleDense` on
101
+ * his lattice, then the level-set rule of {@link sampleWvdbDense} by the
102
+ * filtered active state.
103
+ */
104
+ export function sampleWvdbDenseBox(source, bbox, dimensions, bits = 8) {
105
+ const background = source.background;
106
+ if (!source.bbox || !bbox)
107
+ return new Float32Array(dimensions[0] * dimensions[1] * dimensions[2]).fill(background);
108
+ if (!source.grid) {
109
+ throw new VDBToolsError("VDB_BAD_OPTION", `bakeWvdb: sampling "box" needs the source grid; "${source.name}" has none (use wvdbSourceFromVdbGrid or wvdbSourceFromNvdb)`);
110
+ }
111
+ const { values, active } = vdbResampleDense(source.grid, { bbox, dimensions, filter: "box" });
112
+ if (source.class === "level set") {
113
+ const band = background - (2 * background) / ((1 << bits) - 1);
114
+ for (let i = 0; i < values.length; i++) {
115
+ const v = Number.isFinite(values[i]) ? values[i] : background;
116
+ values[i] = active[i] ? Math.min(Math.max(v, -band), band) : v < 0 ? -background : background;
117
+ }
118
+ }
119
+ else {
120
+ for (let i = 0; i < values.length; i++)
121
+ if (!Number.isFinite(values[i]))
122
+ values[i] = background;
123
+ }
124
+ return values;
125
+ }
126
+ /**
127
+ * Bakes sources to a `.wvdb` with his CLI defaults (128, 3 LODs, 8 bits, sparse, 1024 bricks per page).
128
+ * @param sources The grids to bake, point-sampled in world space.
129
+ * @param options Resolution, box, grid names, sampling and the writer's options ({@link BakeWvdbOptions}).
130
+ */
131
+ export function bakeWvdb(sources, options = {}) {
132
+ const { grids, write } = bakeWvdbVolumes(sources, options);
133
+ return writeWvdb(grids, write);
134
+ }
135
+ /** The volume grids {@link bakeWvdb} writes, and the writer's options (shared with `vdbToWvdb`'s points path). */
136
+ function bakeWvdbVolumes(sources, options) {
137
+ const { resolution = 128, bbox: bakeBBox = null, dimensions, gridNames = null, sampling = "nearest", levelSetSampler = "spec", ...write } = options;
138
+ if (sampling !== "nearest" && sampling !== "box")
139
+ throw new VDBToolsError("VDB_BAD_OPTION", `bakeWvdb: unknown sampling "${String(sampling)}"`);
140
+ if (levelSetSampler !== "spec" && levelSetSampler !== "surface-mean") {
141
+ throw new VDBToolsError("VDB_BAD_OPTION", `bakeWvdb: unknown levelSetSampler "${String(levelSetSampler)}"`);
142
+ }
143
+ if (!Number.isInteger(resolution) || resolution < 1)
144
+ throw new VDBToolsError("VDB_BAD_OPTION", `bakeWvdb: invalid resolution ${resolution}`);
145
+ const selected = gridNames ? sources.filter((s) => gridNames.includes(s.name)) : [...sources];
146
+ const box = bakeBBox ?? unionBox(selected.flatMap((s) => (s.bbox ? [s.bbox] : [])));
147
+ const dims = dimensions ?? wvdbFinestDimensions(box, resolution);
148
+ const bits = write.bits ?? 8;
149
+ const grids = selected.map((s) => ({
150
+ name: s.name,
151
+ class: s.class,
152
+ background: s.background,
153
+ bbox: box,
154
+ finest: {
155
+ dimensions: dims,
156
+ values: s.class === "level set" && levelSetSampler === "surface-mean"
157
+ ? sampleWvdbLevelSetSurfaceMean(s, box, dims, bits)
158
+ : sampling === "box"
159
+ ? sampleWvdbDenseBox(s, box, dims, bits)
160
+ : sampleWvdbDense(s, box, dims, bits),
161
+ },
162
+ }));
163
+ return { grids, write: { ...write, resolution, gridNames, bakeBBox } };
164
+ }
165
+ // ---------------------------------------------------------------------------
166
+ // Sources
167
+ // ---------------------------------------------------------------------------
168
+ /** A parsed `.vdb` grid (axis-aligned map) as a sample source. */
169
+ export function wvdbSourceFromVdbGrid(grid) {
170
+ if (grid.valueType !== "float") {
171
+ throw new VDBToolsError("VDB_UNSUPPORTED_GRID_TYPE", `wvdbSourceFromVdbGrid: grid "${grid.name}" is a ${grid.valueType} grid; only float grids can be baked ` +
172
+ `(vdbToWvdb skips the others)`);
173
+ }
174
+ const m = grid.transform.matrix;
175
+ if (m[1] !== 0 || m[2] !== 0 || m[4] !== 0 || m[6] !== 0 || m[8] !== 0 || m[9] !== 0) {
176
+ throw new VDBUnsupportedError(`wvdbSourceFromVdbGrid: grid "${grid.name}" has a rotated map; only axis-aligned maps are supported`);
177
+ }
178
+ const scale = [m[0], m[5], m[10]];
179
+ const translation = [m[3], m[7], m[11]];
180
+ const inverse = scale.map((s) => 1 / s);
181
+ const lo = [Infinity, Infinity, Infinity];
182
+ const hi = [-Infinity, -Infinity, -Infinity];
183
+ for (const leaf of grid.iterLeaves()) {
184
+ for (let offset = 0; offset < 512; offset++) {
185
+ if (((leaf.valueMask[offset >>> 5] >>> (offset & 31)) & 1) === 0)
186
+ continue;
187
+ const ijk = [leaf.origin[0] + (offset >> 6), leaf.origin[1] + ((offset >> 3) & 7), leaf.origin[2] + (offset & 7)];
188
+ for (let a = 0; a < 3; a++) {
189
+ lo[a] = Math.min(lo[a], ijk[a]);
190
+ hi[a] = Math.max(hi[a], ijk[a]);
191
+ }
192
+ }
193
+ }
194
+ let bbox = null;
195
+ if (lo[0] <= hi[0]) {
196
+ const a = [0, 1, 2].map((i) => lo[i] * scale[i] + translation[i]);
197
+ const b = [0, 1, 2].map((i) => hi[i] * scale[i] + translation[i]);
198
+ bbox = [a.map((v, i) => Math.min(v, b[i])), a.map((v, i) => Math.max(v, b[i]))];
199
+ }
200
+ const cls = grid.metadata["class"];
201
+ const ijk = [0, 0, 0];
202
+ return {
203
+ name: grid.name,
204
+ class: typeof cls === "string" ? cls : "unknown",
205
+ background: grid.background,
206
+ bbox,
207
+ sample(world) {
208
+ for (let a = 0; a < 3; a++)
209
+ ijk[a] = Math.round((world[a] - translation[a]) * inverse[a]);
210
+ return grid.readValue(ijk);
211
+ },
212
+ index: {
213
+ // His GridTransform scale-translate maps: (v - translation) * scaleInverse.
214
+ toIndex(world, out) {
215
+ for (let a = 0; a < 3; a++)
216
+ out[a] = (world[a] - translation[a]) * inverse[a];
217
+ return out;
218
+ },
219
+ toIndexVector(v, out) {
220
+ for (let a = 0; a < 3; a++)
221
+ out[a] = v[a] * inverse[a];
222
+ return out;
223
+ },
224
+ voxel: (p) => grid.readValue(p),
225
+ },
226
+ grid,
227
+ };
228
+ }
229
+ const NANO_CLASS = { 1: "level set", 2: "fog volume", 3: "staggered" };
230
+ /** A NanoVDB FLOAT/Fp8/FpN grid image as a sample source, read through the CPU oracle (`readValue`). */
231
+ export function wvdbSourceFromNvdb(gridWords) {
232
+ const view = new DataView(gridWords.buffer, gridWords.byteOffset, gridWords.byteLength);
233
+ const nameBytes = new Uint8Array(gridWords.buffer, gridWords.byteOffset + GRID_OFF_GRID_NAME, GRID_NAME_MAX);
234
+ const nul = nameBytes.indexOf(0);
235
+ const name = new TextDecoder().decode(nameBytes.subarray(0, nul < 0 ? GRID_NAME_MAX : nul));
236
+ const gridType = view.getUint32(GRID_OFF_GRID_TYPE, true);
237
+ const cls = NANO_CLASS[view.getUint32(GRID_OFF_GRID_CLASS, true)] ?? "unknown";
238
+ const mat = Array.from({ length: 9 }, (_, i) => view.getFloat64(GRID_OFF_MAP + MAP_OFF_MATD + i * 8, true));
239
+ const inv = Array.from({ length: 9 }, (_, i) => view.getFloat64(GRID_OFF_MAP + MAP_OFF_INVMATD + i * 8, true));
240
+ const vec = Array.from({ length: 3 }, (_, i) => view.getFloat64(GRID_OFF_MAP + MAP_OFF_VECD + i * 8, true));
241
+ const root = GRID_SIZE + Number(view.getBigUint64(GRID_SIZE + TREE_OFF_NODE_OFFSET_ROOT, true));
242
+ const lo = [0, 1, 2].map((i) => view.getInt32(root + ROOT_OFF_BBOX_MIN + i * 4, true));
243
+ const hi = [0, 1, 2].map((i) => view.getInt32(root + ROOT_OFF_BBOX_MAX + i * 4, true));
244
+ const background = view.getFloat32(root + gridTypeConstantsForId(gridType).root_off_background, true);
245
+ const toWorld = (p) => [0, 1, 2].map((r) => mat[r * 3] * p[0] + mat[r * 3 + 1] * p[1] + mat[r * 3 + 2] * p[2] + vec[r]);
246
+ let bbox = null;
247
+ if (lo[0] <= hi[0] && lo[1] <= hi[1] && lo[2] <= hi[2]) {
248
+ const min = [Infinity, Infinity, Infinity];
249
+ const max = [-Infinity, -Infinity, -Infinity];
250
+ for (let c = 0; c < 8; c++) {
251
+ const w = toWorld([c & 1 ? hi[0] : lo[0], c & 2 ? hi[1] : lo[1], c & 4 ? hi[2] : lo[2]]);
252
+ for (let a = 0; a < 3; a++) {
253
+ min[a] = Math.min(min[a], w[a]);
254
+ max[a] = Math.max(max[a], w[a]);
255
+ }
256
+ }
257
+ bbox = [min, max];
258
+ }
259
+ const ijk = [0, 0, 0];
260
+ return {
261
+ name,
262
+ class: cls,
263
+ background,
264
+ bbox,
265
+ sample(world) {
266
+ const p = [world[0] - vec[0], world[1] - vec[1], world[2] - vec[2]];
267
+ for (let r = 0; r < 3; r++)
268
+ ijk[r] = Math.round(inv[r * 3] * p[0] + inv[r * 3 + 1] * p[1] + inv[r * 3 + 2] * p[2]);
269
+ return vdbReadValueCpu(gridWords, ijk);
270
+ },
271
+ index: {
272
+ toIndex(world, out) {
273
+ const p0 = world[0] - vec[0];
274
+ const p1 = world[1] - vec[1];
275
+ const p2 = world[2] - vec[2];
276
+ for (let r = 0; r < 3; r++)
277
+ out[r] = inv[r * 3] * p0 + inv[r * 3 + 1] * p1 + inv[r * 3 + 2] * p2;
278
+ return out;
279
+ },
280
+ toIndexVector(v, out) {
281
+ const [v0, v1, v2] = v;
282
+ for (let r = 0; r < 3; r++)
283
+ out[r] = inv[r * 3] * v0 + inv[r * 3 + 1] * v1 + inv[r * 3 + 2] * v2;
284
+ return out;
285
+ },
286
+ voxel: (p) => vdbReadValueCpu(gridWords, p),
287
+ },
288
+ grid: gridWords,
289
+ };
290
+ }
291
+ /**
292
+ * A parsed point data grid as a `.wvdb` points grid (G14b, his `encodePointGrid`): world positions and `Cd` in
293
+ * the grid's point order, every n-th point above `maxPoints` (`vdbPointRenderData`'s stride rule, his
294
+ * `createPointData`), the source count and his spacing. `writeWvdb` then splits it into LODs (§3.5).
295
+ *
296
+ * @param grid A point data grid from `parseVdb`.
297
+ * @param maxPoints Keep every `ceil(total / maxPoints)`-th point above this many (default 4,000,000).
298
+ */
299
+ export function wvdbPointsFromVdbGrid(grid, maxPoints) {
300
+ const data = vdbPointRenderData(grid, maxPoints === undefined ? {} : { maxPoints });
301
+ const cls = grid.metadata["class"];
302
+ return {
303
+ type: "points",
304
+ name: grid.name,
305
+ class: typeof cls === "string" ? cls : "unknown",
306
+ positions: data.positions,
307
+ colors: data.colors,
308
+ sourceCount: data.totalCount,
309
+ spacing: data.spacing,
310
+ };
311
+ }
312
+ /**
313
+ * `.vdb` → `.wvdb`, like his `wvdb` CLI with the same options. Given the file
314
+ * bytes, `source.sha256` is their digest. Float grids are baked as volumes and
315
+ * point data grids as points grids (G14b: positions and `Cd`, every n-th point
316
+ * above `maxPoints`, the §3.5 LOD order), in file order; the volume box ignores
317
+ * the points (his `getWVDBBox`). Vector grids are skipped (his CLI bakes them as
318
+ * 3 channels; not ported).
319
+ * @param input The `.vdb` file's bytes, or an already parsed {@link VdbFile}.
320
+ * @param options Baker options and the `source.file` name.
321
+ * @throws VDBToolsError `VDB_UNSUPPORTED_GRID_TYPE` when the file has no float or point data grids.
322
+ */
323
+ export function vdbToWvdb(input, options = {}) {
324
+ const { fileName = "", ...bake } = options;
325
+ let file;
326
+ let source = bake.source;
327
+ if (input instanceof ArrayBuffer || input instanceof Uint8Array) {
328
+ const bytes = input instanceof Uint8Array ? input : new Uint8Array(input);
329
+ const buffer = bytes.byteOffset === 0 && bytes.byteLength === bytes.buffer.byteLength && bytes.buffer instanceof ArrayBuffer
330
+ ? bytes.buffer
331
+ : bytes.slice().buffer;
332
+ file = parseVdb(buffer);
333
+ source ??= { file: fileName, sha256: sha256Hex(bytes) };
334
+ }
335
+ else {
336
+ file = input;
337
+ }
338
+ // His getBakedGrids: the selected scalar and point data grids, in file order.
339
+ const names = bake.gridNames ?? null;
340
+ const baked = file.grids.filter((g) => (g.valueType === "float" || g.valueType === "ptdataidx32") && (!names || names.includes(g.name)));
341
+ if (!file.grids.some((g) => g.valueType === "float" || g.valueType === "ptdataidx32")) {
342
+ throw new VDBToolsError("VDB_UNSUPPORTED_GRID_TYPE", "vdbToWvdb: the file has no float or point data grids to bake");
343
+ }
344
+ const options2 = { ...bake, ...(source ? { source } : {}) };
345
+ if (!baked.some((g) => g.valueType === "ptdataidx32"))
346
+ return bakeWvdb(file.grids.filter((g) => g.valueType === "float").map(wvdbSourceFromVdbGrid), options2);
347
+ const floats = baked.filter((g) => g.valueType === "float");
348
+ const { grids: volumes, write } = bakeWvdbVolumes(floats.map(wvdbSourceFromVdbGrid), options2);
349
+ const grids = baked.map((g) => g.valueType === "float" ? volumes[floats.indexOf(g)] : wvdbPointsFromVdbGrid(g, bake.maxPoints));
350
+ return writeWvdb(grids, write);
351
+ }
352
+ /**
353
+ * NanoVDB grid image(s) → `.wvdb`, sampled through the CPU oracle.
354
+ * @param images One grid image or several.
355
+ * @param options Baker options.
356
+ */
357
+ export function nvdbToWvdb(images, options = {}) {
358
+ const list = images instanceof Uint32Array ? [images] : images;
359
+ return bakeWvdb(list.map(wvdbSourceFromNvdb), options);
360
+ }
361
+ //# sourceMappingURL=bake.js.map
@@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C;IACF,OAAO,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AACjC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,MAA4C,EAAE,UAA2B,EAAE;IACpG,MAAM,IAAI,GAAG,MAAM,YAAY,WAAW,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IAC/D,OAAO,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,kBAAkB,CAAC,EAAE,OAAO,CAAC,CAAC;AACzD,CAAC","sourcesContent":["/**\n * bake.ts — resample sparse grids (a parsed `.vdb`, or a NanoVDB grid image\n * through the CPU oracle) to dense levels and write a `.wvdb`.\n *\n * Portions derived from mjurczyk/openvdb (MIT), commit 75e7345:\n * `src/wvdb/bake.js` (getWVDBBox, getFinestDimensions, forEachTexel,\n * sampleScalarGrid, the level-set band limit, getBakedGrids and\n * encodePointGrid: point data grids become points grids in file order, G14b)\n * and `src/wvdb/cli.js` (the `source` member). His sampling is reproduced, including its arithmetic order:\n * - one shared world box for all grids: the union of the grids' active-voxel\n * index boxes (voxel centres, so `max` is the last voxel, not one past it)\n * mapped to world space, unless `bbox` is given;\n * - the finest LOD has `resolution` voxels on the longest box side, the other\n * sides `max(1, round(side * resolution / longest))` (§3.2.1);\n * - **point sampling, no prefilter** (§3.2.2): world position of voxel centre\n * `min + ((i + 0.5) / X) * size`, mapped to index space with the inverse\n * map, rounded with `Math.round` (halves toward +infinity) and read with\n * the grid's own value lookup (inactive values included). A source much\n * finer than the target resolution aliases; that is his behaviour and the\n * default here (`sampling: 'nearest'`).\n *\n * Options beyond his CLI (K4.13):\n * - `sampling: 'box'` prefilters: each texel is the area-weighted mean of the\n * source voxels its cell covers, on the same lattice (`vdbResampleDense`, the\n * K4.4 `vdbResampleGrid` box filter). Mass is conserved and thin features fade\n * instead of flickering in and out;\n * - `levelSetSampler: 'surface-mean'` samples level sets with his CLI's\n * `sampleLevelSet` (`level-set.ts`), which reproduces his level-set files.\n *\n * Differences from his CLI (also in docs/archive/handoffs/K4-3.md):\n * - by default (`levelSetSampler: 'spec'`) level sets are point-sampled and\n * then encoded by the §8 rule (active: clamp to `±(b - 2b/maxCode)`;\n * inactive: `±b` by sign). His CLI uses `sampleLevelSet` (a surface-aware\n * mean) instead, so level-set bytes differ (DIVERGES V17);\n * - `dimensions` can override the finest LOD size (his pre-0.11 bakes used\n * `resolution`³ for every box, e.g. the committed `smoke.wvdb` and\n * `bunny_cloud.wvdb`; this reproduces them).\n */\n\nimport { VDBToolsError, VDBUnsupportedError } from \"../errors.js\";\nimport { vdbReadValueCpu } from \"../cpu/read-value.js\";\nimport { vdbResampleDense } from \"../nanovdb/resample.js\";\nimport { gridTypeConstantsForId } from \"../cpu/stride-tables.js\";\nimport {\n GRID_NAME_MAX,\n GRID_OFF_GRID_CLASS,\n GRID_OFF_GRID_NAME,\n GRID_OFF_GRID_TYPE,\n GRID_OFF_MAP,\n GRID_SIZE,\n MAP_OFF_INVMATD,\n MAP_OFF_MATD,\n MAP_OFF_VECD,\n ROOT_OFF_BBOX_MAX,\n ROOT_OFF_BBOX_MIN,\n TREE_OFF_NODE_OFFSET_ROOT,\n} from \"../nanovdb/bytes.js\";\nimport { parseVdb } from \"../vdb/parse.js\";\nimport { vdbPointRenderData } from \"../vdb/point-render-data.js\";\nimport type { VdbFile, VdbGrid, VdbPointDataGrid } from \"../vdb/types.js\";\nimport type { WvdbBits, WvdbBox, WvdbSource, WvdbVec3 } from \"./format.js\";\nimport { sampleWvdbLevelSetSurfaceMean, type WvdbIndexAccess } from \"./level-set.js\";\nimport { sha256Hex } from \"./sha256.js\";\nimport {\n writeWvdb,\n type WriteWvdbOptions,\n type WriteWvdbResult,\n type WvdbGridInput,\n type WvdbPointsGridInput,\n type WvdbVolumeGridInput,\n} from \"./write.js\";\n\n/** A grid the baker can point-sample in world space. */\nexport interface WvdbSampleSource {\n /** The grid name (matched by `gridNames`). */\n name: string;\n /** `.wvdb` class string: \"fog volume\", \"level set\", \"staggered\" or \"unknown\". */\n class: string;\n /** The value outside the grid's active voxels. */\n background: number;\n /** World box of the active voxels (voxel centres), or null when the grid has none. */\n bbox: WvdbBox | null;\n /** The grid value (and active state) at the voxel nearest to a world position. */\n sample(world: WvdbVec3): { value: number; active: boolean };\n /** Index-space access, for `levelSetSampler: 'surface-mean'`. The built-in sources have it. */\n index?: WvdbIndexAccess;\n /** The sparse grid behind the source, for `sampling: 'box'`. The built-in sources have it. */\n grid?: Uint32Array | VdbGrid;\n}\n\n/** Options of {@link bakeWvdb}: the writer's options plus the box, resolution and sampling choices. */\nexport interface BakeWvdbOptions extends Omit<WriteWvdbOptions, \"resolution\" | \"bakeBBox\"> {\n /** Voxels on the longest box side of the finest LOD. Default 128. */\n resolution?: number;\n /** One world box for all grids (a sequence box, §10; recorded as `bake.bbox`). Default: union of the grids' boxes. */\n bbox?: WvdbBox | null;\n /** Override the finest LOD dimensions (default from `resolution` and the box). */\n dimensions?: WvdbVec3;\n /**\n * Grids to keep, by name; also recorded as `bake.grids`. Default null (all).\n */\n gridNames?: string[] | null;\n /**\n * Resampling filter. `\"nearest\"` (default): his point sampling. `\"box\"`: the\n * area-weighted mean over each texel's cell (K4.4's box filter; conserves\n * mass, no aliasing when the source is finer than the texels). Needs a source\n * with `grid` (the built-in sources).\n */\n sampling?: WvdbSampling;\n /**\n * How level sets are sampled. `\"spec\"` (default): `sampling`, then the spec\n * §8 rule by active state. `\"surface-mean\"`: his CLI's `sampleLevelSet`\n * (trilinear near the surface, a 4x4x4 mean in texels that cross it), which\n * reproduces his level-set `.wvdb` files; it ignores `sampling`.\n */\n levelSetSampler?: WvdbLevelSetSampler;\n}\n\n/** Resampling filter of the baker: point sampling (`nearest`) or the area-weighted mean of each texel cell (`box`). */\nexport type WvdbSampling = \"nearest\" | \"box\";\n/** How the baker samples level sets: the spec rule (`spec`) or his CLI sampler (`surface-mean`). */\nexport type WvdbLevelSetSampler = \"spec\" | \"surface-mean\";\n\nfunction unionBox(boxes: WvdbBox[]): WvdbBox | null {\n if (!boxes.length) return null;\n const min = [...boxes[0]![0]] as WvdbVec3;\n const max = [...boxes[0]![1]] as WvdbVec3;\n for (const [lo, hi] of boxes.slice(1)) {\n for (let a = 0; a < 3; a++) {\n min[a] = Math.min(min[a]!, lo[a]!);\n max[a] = Math.max(max[a]!, hi[a]!);\n }\n }\n return [min, max];\n}\n\n/** §3.2.1, his `getFinestDimensions`. */\nexport function wvdbFinestDimensions(bbox: WvdbBox | null, resolution: number): WvdbVec3 {\n const size = bbox ? ([0, 1, 2].map((a) => bbox[1][a]! - bbox[0][a]!) as WvdbVec3) : ([0, 0, 0] as WvdbVec3);\n const longest = Math.max(...size);\n if (!(longest > 0)) return [resolution, resolution, resolution];\n return size.map((side) => Math.max(1, Math.round((side * resolution) / longest))) as WvdbVec3;\n}\n\n/** Point-samples one source over the box (his `forEachTexel` + `sampleScalarGrid`). */\nexport function sampleWvdbDense(\n source: WvdbSampleSource,\n bbox: WvdbBox | null,\n dimensions: WvdbVec3,\n bits: WvdbBits = 8,\n): Float32Array {\n const [w, h, d] = dimensions;\n const values = new Float32Array(w * h * d);\n const background = source.background;\n if (!source.bbox || !bbox) return values.fill(background);\n const min = bbox[0];\n const size = [0, 1, 2].map((a) => bbox[1][a]! - min[a]!);\n const isLevelSet = source.class === \"level set\";\n const band = background - (2 * background) / ((1 << bits) - 1);\n const world: WvdbVec3 = [0, 0, 0];\n let o = 0;\n for (let z = 0; z < d; z++) {\n world[2] = ((z + 0.5) / d) * size[2]! + min[2];\n for (let y = 0; y < h; y++) {\n world[1] = ((y + 0.5) / h) * size[1]! + min[1];\n for (let x = 0; x < w; x++) {\n world[0] = ((x + 0.5) / w) * size[0]! + min[0];\n const { value, active } = source.sample(world);\n let v = Number.isFinite(value) ? value : background;\n if (isLevelSet) v = active ? Math.min(Math.max(v, -band), band) : v < 0 ? -background : background;\n values[o++] = v;\n }\n }\n }\n return values;\n}\n\n/**\n * Box-filters one source over the box (`sampling: 'box'`): `vdbResampleDense` on\n * his lattice, then the level-set rule of {@link sampleWvdbDense} by the\n * filtered active state.\n */\nexport function sampleWvdbDenseBox(\n source: WvdbSampleSource,\n bbox: WvdbBox | null,\n dimensions: WvdbVec3,\n bits: WvdbBits = 8,\n): Float32Array {\n const background = source.background;\n if (!source.bbox || !bbox) return new Float32Array(dimensions[0] * dimensions[1] * dimensions[2]).fill(background);\n if (!source.grid) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", `bakeWvdb: sampling \"box\" needs the source grid; \"${source.name}\" has none (use wvdbSourceFromVdbGrid or wvdbSourceFromNvdb)`);\n }\n const { values, active } = vdbResampleDense(source.grid, { bbox, dimensions, filter: \"box\" });\n if (source.class === \"level set\") {\n const band = background - (2 * background) / ((1 << bits) - 1);\n for (let i = 0; i < values.length; i++) {\n const v = Number.isFinite(values[i]!) ? values[i]! : background;\n values[i] = active[i] ? Math.min(Math.max(v, -band), band) : v < 0 ? -background : background;\n }\n } else {\n for (let i = 0; i < values.length; i++) if (!Number.isFinite(values[i]!)) values[i] = background;\n }\n return values;\n}\n\n/**\n * Bakes sources to a `.wvdb` with his CLI defaults (128, 3 LODs, 8 bits, sparse, 1024 bricks per page).\n * @param sources The grids to bake, point-sampled in world space.\n * @param options Resolution, box, grid names, sampling and the writer's options ({@link BakeWvdbOptions}).\n */\nexport function bakeWvdb(sources: readonly WvdbSampleSource[], options: BakeWvdbOptions = {}): WriteWvdbResult {\n const { grids, write } = bakeWvdbVolumes(sources, options);\n return writeWvdb(grids, write);\n}\n\n/** The volume grids {@link bakeWvdb} writes, and the writer's options (shared with `vdbToWvdb`'s points path). */\nfunction bakeWvdbVolumes(\n sources: readonly WvdbSampleSource[],\n options: BakeWvdbOptions,\n): { grids: WvdbVolumeGridInput[]; write: WriteWvdbOptions } {\n const {\n resolution = 128,\n bbox: bakeBBox = null,\n dimensions,\n gridNames = null,\n sampling = \"nearest\",\n levelSetSampler = \"spec\",\n ...write\n } = options;\n if (sampling !== \"nearest\" && sampling !== \"box\") throw new VDBToolsError(\"VDB_BAD_OPTION\", `bakeWvdb: unknown sampling \"${String(sampling)}\"`);\n if (levelSetSampler !== \"spec\" && levelSetSampler !== \"surface-mean\") {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", `bakeWvdb: unknown levelSetSampler \"${String(levelSetSampler)}\"`);\n }\n if (!Number.isInteger(resolution) || resolution < 1) throw new VDBToolsError(\"VDB_BAD_OPTION\", `bakeWvdb: invalid resolution ${resolution}`);\n const selected = gridNames ? sources.filter((s) => gridNames.includes(s.name)) : [...sources];\n const box = bakeBBox ?? unionBox(selected.flatMap((s) => (s.bbox ? [s.bbox] : [])));\n const dims = dimensions ?? wvdbFinestDimensions(box, resolution);\n const bits = write.bits ?? 8;\n const grids: WvdbVolumeGridInput[] = selected.map((s) => ({\n name: s.name,\n class: s.class,\n background: s.background,\n bbox: box,\n finest: {\n dimensions: dims,\n values:\n s.class === \"level set\" && levelSetSampler === \"surface-mean\"\n ? sampleWvdbLevelSetSurfaceMean(s, box, dims, bits)\n : sampling === \"box\"\n ? sampleWvdbDenseBox(s, box, dims, bits)\n : sampleWvdbDense(s, box, dims, bits),\n },\n }));\n return { grids, write: { ...write, resolution, gridNames, bakeBBox } };\n}\n\n// ---------------------------------------------------------------------------\n// Sources\n// ---------------------------------------------------------------------------\n\n/** A parsed `.vdb` grid (axis-aligned map) as a sample source. */\nexport function wvdbSourceFromVdbGrid(grid: VdbGrid): WvdbSampleSource {\n if (grid.valueType !== \"float\") {\n throw new VDBToolsError(\"VDB_UNSUPPORTED_GRID_TYPE\", \n `wvdbSourceFromVdbGrid: grid \"${grid.name}\" is a ${grid.valueType} grid; only float grids can be baked ` +\n `(vdbToWvdb skips the others)`,\n );\n }\n const m = grid.transform.matrix;\n if (m[1] !== 0 || m[2] !== 0 || m[4] !== 0 || m[6] !== 0 || m[8] !== 0 || m[9] !== 0) {\n throw new VDBUnsupportedError(`wvdbSourceFromVdbGrid: grid \"${grid.name}\" has a rotated map; only axis-aligned maps are supported`);\n }\n const scale = [m[0]!, m[5]!, m[10]!];\n const translation = [m[3]!, m[7]!, m[11]!];\n const inverse = scale.map((s) => 1 / s);\n const lo = [Infinity, Infinity, Infinity];\n const hi = [-Infinity, -Infinity, -Infinity];\n for (const leaf of grid.iterLeaves()) {\n for (let offset = 0; offset < 512; offset++) {\n if (((leaf.valueMask[offset >>> 5]! >>> (offset & 31)) & 1) === 0) continue;\n const ijk = [leaf.origin[0] + (offset >> 6), leaf.origin[1] + ((offset >> 3) & 7), leaf.origin[2] + (offset & 7)];\n for (let a = 0; a < 3; a++) {\n lo[a] = Math.min(lo[a]!, ijk[a]!);\n hi[a] = Math.max(hi[a]!, ijk[a]!);\n }\n }\n }\n let bbox: WvdbBox | null = null;\n if (lo[0]! <= hi[0]!) {\n const a = [0, 1, 2].map((i) => lo[i]! * scale[i]! + translation[i]!);\n const b = [0, 1, 2].map((i) => hi[i]! * scale[i]! + translation[i]!);\n bbox = [a.map((v, i) => Math.min(v, b[i]!)) as WvdbVec3, a.map((v, i) => Math.max(v, b[i]!)) as WvdbVec3];\n }\n const cls = grid.metadata[\"class\"];\n const ijk: [number, number, number] = [0, 0, 0];\n return {\n name: grid.name,\n class: typeof cls === \"string\" ? cls : \"unknown\",\n background: grid.background,\n bbox,\n sample(world) {\n for (let a = 0; a < 3; a++) ijk[a] = Math.round((world[a]! - translation[a]!) * inverse[a]!);\n return grid.readValue(ijk);\n },\n index: {\n // His GridTransform scale-translate maps: (v - translation) * scaleInverse.\n toIndex(world, out) {\n for (let a = 0; a < 3; a++) out[a] = (world[a]! - translation[a]!) * inverse[a]!;\n return out;\n },\n toIndexVector(v, out) {\n for (let a = 0; a < 3; a++) out[a] = v[a]! * inverse[a]!;\n return out;\n },\n voxel: (p) => grid.readValue(p),\n },\n grid,\n };\n}\n\nconst NANO_CLASS: Record<number, string> = { 1: \"level set\", 2: \"fog volume\", 3: \"staggered\" };\n\n/** A NanoVDB FLOAT/Fp8/FpN grid image as a sample source, read through the CPU oracle (`readValue`). */\nexport function wvdbSourceFromNvdb(gridWords: Uint32Array): WvdbSampleSource {\n const view = new DataView(gridWords.buffer, gridWords.byteOffset, gridWords.byteLength);\n const nameBytes = new Uint8Array(gridWords.buffer, gridWords.byteOffset + GRID_OFF_GRID_NAME, GRID_NAME_MAX);\n const nul = nameBytes.indexOf(0);\n const name = new TextDecoder().decode(nameBytes.subarray(0, nul < 0 ? GRID_NAME_MAX : nul));\n const gridType = view.getUint32(GRID_OFF_GRID_TYPE, true);\n const cls = NANO_CLASS[view.getUint32(GRID_OFF_GRID_CLASS, true)] ?? \"unknown\";\n const mat = Array.from({ length: 9 }, (_, i) => view.getFloat64(GRID_OFF_MAP + MAP_OFF_MATD + i * 8, true));\n const inv = Array.from({ length: 9 }, (_, i) => view.getFloat64(GRID_OFF_MAP + MAP_OFF_INVMATD + i * 8, true));\n const vec = Array.from({ length: 3 }, (_, i) => view.getFloat64(GRID_OFF_MAP + MAP_OFF_VECD + i * 8, true));\n const root = GRID_SIZE + Number(view.getBigUint64(GRID_SIZE + TREE_OFF_NODE_OFFSET_ROOT, true));\n const lo = [0, 1, 2].map((i) => view.getInt32(root + ROOT_OFF_BBOX_MIN + i * 4, true));\n const hi = [0, 1, 2].map((i) => view.getInt32(root + ROOT_OFF_BBOX_MAX + i * 4, true));\n const background = view.getFloat32(root + gridTypeConstantsForId(gridType).root_off_background, true);\n\n const toWorld = (p: number[]): number[] =>\n [0, 1, 2].map((r) => mat[r * 3]! * p[0]! + mat[r * 3 + 1]! * p[1]! + mat[r * 3 + 2]! * p[2]! + vec[r]!);\n let bbox: WvdbBox | null = null;\n if (lo[0]! <= hi[0]! && lo[1]! <= hi[1]! && lo[2]! <= hi[2]!) {\n const min = [Infinity, Infinity, Infinity];\n const max = [-Infinity, -Infinity, -Infinity];\n for (let c = 0; c < 8; c++) {\n const w = toWorld([c & 1 ? hi[0]! : lo[0]!, c & 2 ? hi[1]! : lo[1]!, c & 4 ? hi[2]! : lo[2]!]);\n for (let a = 0; a < 3; a++) {\n min[a] = Math.min(min[a]!, w[a]!);\n max[a] = Math.max(max[a]!, w[a]!);\n }\n }\n bbox = [min as WvdbVec3, max as WvdbVec3];\n }\n const ijk: [number, number, number] = [0, 0, 0];\n return {\n name,\n class: cls,\n background,\n bbox,\n sample(world) {\n const p = [world[0] - vec[0]!, world[1] - vec[1]!, world[2] - vec[2]!];\n for (let r = 0; r < 3; r++) ijk[r] = Math.round(inv[r * 3]! * p[0]! + inv[r * 3 + 1]! * p[1]! + inv[r * 3 + 2]! * p[2]!);\n return vdbReadValueCpu(gridWords, ijk);\n },\n index: {\n toIndex(world, out) {\n const p0 = world[0] - vec[0]!;\n const p1 = world[1] - vec[1]!;\n const p2 = world[2] - vec[2]!;\n for (let r = 0; r < 3; r++) out[r] = inv[r * 3]! * p0 + inv[r * 3 + 1]! * p1 + inv[r * 3 + 2]! * p2;\n return out;\n },\n toIndexVector(v, out) {\n const [v0, v1, v2] = v;\n for (let r = 0; r < 3; r++) out[r] = inv[r * 3]! * v0 + inv[r * 3 + 1]! * v1 + inv[r * 3 + 2]! * v2;\n return out;\n },\n voxel: (p) => vdbReadValueCpu(gridWords, p),\n },\n grid: gridWords,\n };\n}\n\n/** Options of {@link vdbToWvdb}: the baker's options plus the source file name. */\nexport interface VdbToWvdbOptions extends BakeWvdbOptions {\n /** `source.file` (the name without directories). Default \"\". */\n fileName?: string;\n}\n\n/**\n * A parsed point data grid as a `.wvdb` points grid (G14b, his `encodePointGrid`): world positions and `Cd` in\n * the grid's point order, every n-th point above `maxPoints` (`vdbPointRenderData`'s stride rule, his\n * `createPointData`), the source count and his spacing. `writeWvdb` then splits it into LODs (§3.5).\n *\n * @param grid A point data grid from `parseVdb`.\n * @param maxPoints Keep every `ceil(total / maxPoints)`-th point above this many (default 4,000,000).\n */\nexport function wvdbPointsFromVdbGrid(grid: VdbPointDataGrid, maxPoints?: number): WvdbPointsGridInput {\n const data = vdbPointRenderData(grid, maxPoints === undefined ? {} : { maxPoints });\n const cls = grid.metadata[\"class\"];\n return {\n type: \"points\",\n name: grid.name,\n class: typeof cls === \"string\" ? cls : \"unknown\",\n positions: data.positions,\n colors: data.colors,\n sourceCount: data.totalCount,\n spacing: data.spacing,\n };\n}\n\n/**\n * `.vdb` → `.wvdb`, like his `wvdb` CLI with the same options. Given the file\n * bytes, `source.sha256` is their digest. Float grids are baked as volumes and\n * point data grids as points grids (G14b: positions and `Cd`, every n-th point\n * above `maxPoints`, the §3.5 LOD order), in file order; the volume box ignores\n * the points (his `getWVDBBox`). Vector grids are skipped (his CLI bakes them as\n * 3 channels; not ported).\n * @param input The `.vdb` file's bytes, or an already parsed {@link VdbFile}.\n * @param options Baker options and the `source.file` name.\n * @throws VDBToolsError `VDB_UNSUPPORTED_GRID_TYPE` when the file has no float or point data grids.\n */\nexport function vdbToWvdb(input: ArrayBuffer | Uint8Array | VdbFile, options: VdbToWvdbOptions = {}): WriteWvdbResult {\n const { fileName = \"\", ...bake } = options;\n let file: VdbFile;\n let source: WvdbSource | undefined = bake.source;\n if (input instanceof ArrayBuffer || input instanceof Uint8Array) {\n const bytes = input instanceof Uint8Array ? input : new Uint8Array(input);\n const buffer = bytes.byteOffset === 0 && bytes.byteLength === bytes.buffer.byteLength && bytes.buffer instanceof ArrayBuffer\n ? bytes.buffer\n : bytes.slice().buffer;\n file = parseVdb(buffer);\n source ??= { file: fileName, sha256: sha256Hex(bytes) };\n } else {\n file = input;\n }\n // His getBakedGrids: the selected scalar and point data grids, in file order.\n const names = bake.gridNames ?? null;\n const baked = file.grids.filter((g) => (g.valueType === \"float\" || g.valueType === \"ptdataidx32\") && (!names || names.includes(g.name)));\n if (!file.grids.some((g) => g.valueType === \"float\" || g.valueType === \"ptdataidx32\")) {\n throw new VDBToolsError(\"VDB_UNSUPPORTED_GRID_TYPE\", \"vdbToWvdb: the file has no float or point data grids to bake\");\n }\n const options2 = { ...bake, ...(source ? { source } : {}) };\n if (!baked.some((g) => g.valueType === \"ptdataidx32\")) return bakeWvdb(file.grids.filter((g) => g.valueType === \"float\").map(wvdbSourceFromVdbGrid), options2);\n const floats = baked.filter((g) => g.valueType === \"float\");\n const { grids: volumes, write } = bakeWvdbVolumes(floats.map(wvdbSourceFromVdbGrid), options2);\n const grids: WvdbGridInput[] = baked.map((g) =>\n g.valueType === \"float\" ? volumes[floats.indexOf(g)]! : wvdbPointsFromVdbGrid(g as VdbPointDataGrid, bake.maxPoints),\n );\n return writeWvdb(grids, write);\n}\n\n/**\n * NanoVDB grid image(s) → `.wvdb`, sampled through the CPU oracle.\n * @param images One grid image or several.\n * @param options Baker options.\n */\nexport function nvdbToWvdb(images: Uint32Array | readonly Uint32Array[], options: BakeWvdbOptions = {}): WriteWvdbResult {\n const list = images instanceof Uint32Array ? [images] : images;\n return bakeWvdb(list.map(wvdbSourceFromNvdb), options);\n}\n"]}
@@ -0,0 +1,191 @@
1
+ import type { WvdbBox, WvdbVec3 } from "./format.js";
2
+ import type { WvdbFile, WvdbVolumeGrid, WvdbVolumeLevel } from "./read.js";
3
+ /** One uploaded 3D texture: texels x fastest, then y, then z. */
4
+ export interface WvdbDenseTexture {
5
+ /** 1 byte per texel (`r8unorm`) or 4 (`rgba8unorm`). */
6
+ readonly data: Uint8Array<ArrayBuffer>;
7
+ /** Texels per axis. */
8
+ readonly dimensions: WvdbVec3;
9
+ /** The WebGPU texture format the bytes are laid out for. */
10
+ readonly format: "r8unorm" | "rgba8unorm";
11
+ /** Bytes per texel (1 or 4). */
12
+ readonly texelBytes: 1 | 4;
13
+ /** CPU box mip atlas (levels 1..`levels` side by side on x), or null without mipmaps. */
14
+ readonly mip: WvdbMipAtlas | null;
15
+ /**
16
+ * K4.22: a partially streamed LOD's bricks to fill from a coarser LOD (`wvdbDensePartialVolume` with
17
+ * `fill: 'upsample'`), or absent / null. `data` and `mip` then hold the background in those bricks; the core's
18
+ * dense source fills them on the GPU, `wvdbDenseResolve` on the CPU.
19
+ */
20
+ readonly fill?: WvdbDenseFill | null;
21
+ }
22
+ /**
23
+ * K4.22: the bricks of a partially streamed LOD that are stored but not decoded yet, and the coarser LOD's texels
24
+ * to fill them with (his `wvdbKernel` upsample: trilinear, texel centres aligned, edges clamped).
25
+ */
26
+ export interface WvdbDenseFill {
27
+ /** One bit per brick of the texture (brick index x fastest; word `index >> 5`, bit `index & 31`). */
28
+ readonly pending: Uint32Array;
29
+ /** Bricks set in `pending`. */
30
+ readonly count: number;
31
+ /** The coarser LOD's texels in the texture's format (a complete LOD), and their size. */
32
+ readonly from: {
33
+ readonly data: Uint8Array<ArrayBuffer>;
34
+ readonly dimensions: WvdbVec3;
35
+ };
36
+ /**
37
+ * The mip atlas of the filled texture: `'box'` builds every level from the filled texels (his frameMipmaps);
38
+ * `'coarse'` takes level 1 of the pending bricks from the coarser LOD itself (the LOD a `.wvdb` bake makes by a
39
+ * 2x box filter of this one), when its size is level 1's, so a far view of a pending brick is the coarser LOD,
40
+ * not a blur of its upsample. Default `'coarse'`.
41
+ */
42
+ readonly mips?: "coarse" | "box";
43
+ }
44
+ /** His `packAtlas` output (frameMipmaps.js L65–88). */
45
+ export interface WvdbMipAtlas {
46
+ /** The atlas texels, x fastest. */
47
+ readonly data: Uint8Array<ArrayBuffer>;
48
+ /** Atlas size in texels per axis. */
49
+ readonly dimensions: WvdbVec3;
50
+ /** Levels in the atlas (level 0 is the texture itself). */
51
+ readonly levels: number;
52
+ }
53
+ /** Density statistics as his `getDensityStats` (FrameVolume.js L50–62): sum of non-zero texels / 255, and their count. */
54
+ export interface WvdbTexelStats {
55
+ /** Sum of the non-zero texels, each divided by 255. */
56
+ readonly sum: number;
57
+ /** Number of non-zero texels. */
58
+ readonly count: number;
59
+ }
60
+ /** A `.wvdb` LOD as the dense textures his renderer uploads (R1 §4.2 `vdbDenseSource` input). */
61
+ export interface WvdbDenseVolume {
62
+ /** Discriminant: a dense (texture) volume. */
63
+ readonly kind: "dense";
64
+ /** The only dense normalization: 8-bit, `clamp(value / scale, 0, 1)` (R1 §4.3). */
65
+ readonly normalize: "clamp01";
66
+ /** The LOD these textures were built from (0 is the coarsest). */
67
+ readonly lod: number;
68
+ /** Texels of the density texture; aux textures have the same size. */
69
+ readonly dimensions: WvdbVec3;
70
+ /** World box of the density grid (`grid.bbox`), or null for an empty grid. */
71
+ readonly bbox: WvdbBox | null;
72
+ /** The density texture (R8). */
73
+ readonly density: WvdbDenseTexture;
74
+ /** The mask texture (R8), or null without a mask grid. */
75
+ readonly mask: WvdbDenseTexture | null;
76
+ /** The albedo texture (RGBA8), or null without an albedo grid. */
77
+ readonly albedo: WvdbDenseTexture | null;
78
+ /** The emission texture (R8), or null without an emission grid. */
79
+ readonly emission: WvdbDenseTexture | null;
80
+ /** The stats his volume ends up with: baked (header) when present and the scale is 1, else from the texels. */
81
+ readonly densityStats: WvdbTexelStats;
82
+ /** Where `densityStats` came from: the file header (`baked`) or the texels. */
83
+ readonly densityStatsSource: "baked" | "texels";
84
+ /** `getMeanDensity` of the one volume: `sum / count`, 0 when empty. */
85
+ readonly meanDensity: number;
86
+ /** Largest density texel / 255. */
87
+ readonly maxDensity: number;
88
+ /** Non-zero density texels. */
89
+ readonly activeTexels: number;
90
+ /** The names of the `.wvdb` grids each texture was read from. */
91
+ readonly gridNames: {
92
+ readonly density: string;
93
+ readonly mask?: string;
94
+ readonly albedo?: string;
95
+ readonly emission?: string;
96
+ };
97
+ }
98
+ /** Options of {@link wvdbDenseVolume}: which grids fill which channel, the LOD, scales and mipmaps. */
99
+ export interface WvdbDenseOptions {
100
+ /** Density grid. Default: the grid named `density`, else the first volume grid (his frame.js L519). */
101
+ density?: string;
102
+ /** Scalar grid read as a mask (multiplies density). */
103
+ mask?: string;
104
+ /** Vector grid read as base colour (RGBA8). */
105
+ albedo?: string;
106
+ /** Scalar grid read as emission (`value / scale`; use `scales` for his `emissiveScale`). */
107
+ emission?: string;
108
+ /** LOD to build. Default: the finest LOD the file has decoded. */
109
+ lod?: number;
110
+ /** His `WVDBLoader.setGridScales`: `{ gridName: scale }`, scalar values divide by it (default 1). */
111
+ scales?: Readonly<Record<string, number>>;
112
+ /** Build the CPU box mip atlas (his `FrameVolume` `mipmaps`, default true). */
113
+ mipmaps?: boolean;
114
+ }
115
+ /** WVDBReader.js L128 / wvdbKernel.js L20: `(Math.min(Math.max(value, 0.0), 1.0) * 255.0) | 0`. */
116
+ export declare const wvdbToByte: (value: number) => number;
117
+ /**
118
+ * The 8-bit texels his worker kernel produces for one decoded LOD (wvdbKernel.js
119
+ * `toTexels` L24–58, `writeBricks` L89–119 over a background fill L255–256 with
120
+ * `getBackgroundTexel` WVDBReader.js L131–137). Our decoded level already holds
121
+ * the background where no brick is stored, so the per-voxel rule is applied to
122
+ * the whole dense array. Scalar: 1 byte; vector: RGBA8 with alpha 255 (no scale).
123
+ */
124
+ export declare function wvdbTexels(grid: WvdbVolumeGrid, level: WvdbVolumeLevel, scale?: number): Uint8Array<ArrayBuffer>;
125
+ /** FrameVolume.js L50–62 `getDensityStats`. */
126
+ export declare function wvdbTexelStats(data: Uint8Array): WvdbTexelStats;
127
+ /** frameMipmaps.js L14 `getLevelSize` (ceil sizes; the WebGL path floors, R1 §8 quality note 5). */
128
+ export declare const wvdbMipLevelSize: (size: number, level: number) => number;
129
+ /** frameMipmaps.js L16–17 `getMipLevelCount`. */
130
+ export declare const wvdbMipLevelCount: (width: number, height: number, depth: number) => number;
131
+ /**
132
+ * The mip atlas size and level count `wvdbMipAtlas` gives for a texture of `dimensions`, without building it
133
+ * (null when the texture has one texel on every side).
134
+ */
135
+ export declare function wvdbMipAtlasLayout(dimensions: readonly number[]): {
136
+ dimensions: WvdbVec3;
137
+ levels: number;
138
+ } | null;
139
+ /**
140
+ * frameMipmaps.js L90–106 `buildAtlas` + L65–88 `packAtlas`: levels 1..n (n =
141
+ * `ceil(log2(max side))`), level l at x = atlasWidth − atlasWidth / 2^(l−1);
142
+ * atlas width 2^max(ceil(log2 width), n), height and depth those of level 1.
143
+ * Null when the texture has one texel on every side.
144
+ */
145
+ export declare function wvdbMipAtlas(data: Uint8Array<ArrayBuffer>, dimensions: readonly number[], channels: 1 | 4,
146
+ /** K4.22: edits level 1 (texels x fastest) before the higher levels are built from it. */
147
+ editLevel1?: (level: {
148
+ data: Uint8Array<ArrayBuffer>;
149
+ width: number;
150
+ height: number;
151
+ depth: number;
152
+ }) => void): WvdbMipAtlas | null;
153
+ /**
154
+ * K4.22: a texture whose `fill` bricks are still background. Its mip atlas is built on first read of `mip.data`
155
+ * (from the background-filled texels): the core's dense source builds the filled atlas on the GPU and never reads it.
156
+ */
157
+ export declare function wvdbDenseFillTexture(data: Uint8Array<ArrayBuffer>, dimensions: WvdbVec3, texelBytes: 1 | 4, mipmaps: boolean, fill: WvdbDenseFill | null): WvdbDenseTexture;
158
+ /** @internal How {@link wvdbDenseAssemble} reads each grid's level and makes its texture (K4.22: partial LODs). */
159
+ export interface WvdbDenseAssembly {
160
+ /** The level of `grid` to upload. */
161
+ level(grid: WvdbVolumeGrid, role: string): WvdbVolumeLevel;
162
+ /** The texture of `grid` from its texels (default: {@link denseTexture} with a CPU atlas). */
163
+ texture?(grid: WvdbVolumeGrid, level: WvdbVolumeLevel, data: Uint8Array<ArrayBuffer>, texelBytes: 1 | 4, mipmaps: boolean, scale: number): WvdbDenseTexture;
164
+ }
165
+ /**
166
+ * Builds the dense textures his renderer would upload for one LOD of a decoded
167
+ * `.wvdb` file: density (R8), optional mask (R8), albedo (RGBA8) and emission
168
+ * (R8), each with its CPU box mip atlas, plus the density stats his volume uses
169
+ * for `normalizeDensity` (`meanDensity`).
170
+ * @param file A decoded `.wvdb` ({@link readWvdb}) with the LOD's levels.
171
+ * @param o Which grids to read, the LOD, scales and mipmaps.
172
+ */
173
+ export declare function wvdbDenseVolume(file: WvdbFile, o?: WvdbDenseOptions): WvdbDenseVolume;
174
+ /** @internal The density grid {@link wvdbDenseVolume} reads (`o.density`, else `density`, else the first volume grid). */
175
+ export declare function wvdbDenseDensityGrid(file: WvdbFile, o: Pick<WvdbDenseOptions, "density">): WvdbVolumeGrid;
176
+ /**
177
+ * @internal {@link wvdbDenseVolume}'s assembly from one level per grid (`how.level`): texels, aux channels, stats.
178
+ * K4.22's partial volumes pass the stream event's levels and textures with a `fill`.
179
+ */
180
+ export declare function wvdbDenseAssemble(file: WvdbFile, o: WvdbDenseOptions, lod: number, how: WvdbDenseAssembly): WvdbDenseVolume;
181
+ /** FrameVolume.js L561–568 `getDensityScale`: `densityScale / meanDensity` with `normalizeDensity`. */
182
+ export declare function wvdbDensityScale(volume: Pick<WvdbDenseVolume, "meanDensity">, densityScale?: number, normalizeDensity?: boolean): number;
183
+ /**
184
+ * CPU twin of the dense source's read at `uvw` (already offset and wrapped) and
185
+ * `lod` (frameShaderChunks.js L849–877 `sampleMipmapped` / `sample3D`): hardware
186
+ * trilinear on the 8-bit texels (as normalized floats), and with mip levels a
187
+ * linear blend of the two nearest levels from the atlas. Real GPUs filter with
188
+ * limited weight precision (typically 8 fractional bits), so compare with a
189
+ * tolerance of about 1/255 of the local value range.
190
+ */
191
+ export declare function sampleWvdbDenseTexture(tex: WvdbDenseTexture, uvw: readonly number[], lod?: number, channel?: number): number;