@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,329 @@
1
+ /**
2
+ * quantize.ts — re-encode a Float or Half NanoVDB grid image as Fp4, Fp8, Fp16, FpN, Half or Float.
3
+ *
4
+ * Quantization is a leaf-value-representation change only: topology, masks,
5
+ * internal-node tables/stats, GridData and the transform are unchanged. So
6
+ * `quantize` reads the source FLOAT image's leaves (each: 8-aligned origin,
7
+ * all 512 values, value mask), its active tiles (root, upper, lower; kept as
8
+ * tiles since K4.1 — tile values stay plain f32 in Fp8/FpN grids) and its
9
+ * GridData transform/background, then re-runs the leaf-iterator build path
10
+ * ({@link vdbBuildFromLeavesDetailed}) with the chosen quantizing {@link VDBLeafCodec}. The result satisfies the repo's proven decoders
11
+ * (`read-value.ts` `leafFp*ReadFloat`, `pnanovdb.wgsl`).
12
+ *
13
+ * - `fp4` / `fp8` / `fp16` — fixed 4/8/16-bit codes; per-leaf quantum = (max-min)/(2^bits-1).
14
+ * The CreateNanoGrid rules Fp8 uses (min/quantum over all 512 values, round-to-nearest, no
15
+ * dither); `tolerance` is ignored. No native Fp4/Fp16 fixtures exist, so these are verified
16
+ * by decoder round-trip and GPU parity, not byte-compared to `nanovdb_convert`.
17
+ * - `fpn` — per-leaf variable bit-width, smallest of 1/2/4/8/16 bits whose
18
+ * dequantized values stay within `tolerance` (default: native's FogVolume 0.01).
19
+ * - `half` (K7.H) — NanoVDB `GridType::Half` (NanoVDB 13.2): every value (leaf
20
+ * voxels, tiles, background) becomes the nearest IEEE binary16 (round to
21
+ * nearest even, `|v| > 65504` to infinity; NanoVDB `math::FloatToHalf`), as
22
+ * `tools::createNanoGrid<FloatGrid, Half>` writes it; min/max stats are
23
+ * binary16, ave/stddev f32 over the stored halves. Relative error <= 2^-11 in
24
+ * the normal range (6.1e-5 to 65504); absolute <= 2^-25 below it. `tolerance`
25
+ * is ignored. Cross-checked against native NanoVDB v14.0.0
26
+ * (`docker/fixture-bake/bake_half.cpp`, `test/tools/half-native.test.ts`).
27
+ *
28
+ * - `float` (K7.H1) — plain f32 leaves: widens a Half grid exactly (Half ->
29
+ * Float -> Half is the identity), or re-lays out a Float grid.
30
+ *
31
+ * Sources are Float or Half grids (K7.H1; Half values widen to f32 exactly);
32
+ * quantized sources throw, since re-quantizing loses precision twice.
33
+ */
34
+ import { VDBToolsError } from "../errors.js";
35
+ import { FLOAT_LAYOUT, GRID_OFF_GRID_CLASS, GRID_OFF_GRID_NAME, GRID_OFF_GRID_TYPE, GRID_OFF_MAP, GRID_OFF_VOXEL_SIZE, GRID_SIZE, GRID_TYPE_FLOAT, GRID_TYPE_HALF, HALF_LAYOUT, LEAF_OFF_VALUE_MASK, LEAF_TABLE_COUNT, LOWER_OFF_CHILD_MASK, LOWER_TABLE_COUNT, MAP_OFF_VECD, NODE_OFF_VALUE_MASK, ROOT_OFF_TABLE_SIZE, ROOT_TILE_OFF_CHILD, ROOT_TILE_OFF_KEY, ROOT_TILE_OFF_STATE, TREE_OFF_NODE_OFFSET_ROOT, UPPER_OFF_CHILD_MASK, UPPER_TABLE_COUNT, } from "./bytes.js";
36
+ import { VDB_FLOAT_LEAF_CODEC, VDB_FP4_LEAF_CODEC, VDB_FP8_LEAF_CODEC, VDB_FP16_LEAF_CODEC, VDB_HALF_LEAF_CODEC, vdbMakeFpNLeafCodec, } from "./leaf-codec.js";
37
+ import { vdbHalfToFloat } from "./half.js";
38
+ import { vdbBuildFromLeavesDetailed } from "./serialize.js";
39
+ /**
40
+ * Re-encodes a Float or Half grid image (or built grid) as Fp4/Fp8/Fp16/FpN, Half or Float. Returns a new image.
41
+ *
42
+ * @param input A Float or Half grid image, or a built grid.
43
+ * @param mode Target encoding.
44
+ * @param tolerance Absolute error bound for `'fpn'` (leaf bit-width is chosen to meet it); ignored by the other modes.
45
+ * @param options Topology options (leaf collapsing).
46
+ */
47
+ export function vdbQuantize(input, mode, tolerance, options = {}) {
48
+ return vdbQuantizeDetailed(input, mode, tolerance, options).image;
49
+ }
50
+ /**
51
+ * As {@link vdbQuantize}, but returns the computed metadata alongside the image.
52
+ *
53
+ * @param input A Float or Half grid image, or a built grid.
54
+ * @param mode Target encoding.
55
+ * @param tolerance Absolute error bound for `'fpn'`; ignored by the fixed-width modes.
56
+ * @param options Topology options (leaf collapsing).
57
+ */
58
+ export function vdbQuantizeDetailed(input, mode, tolerance, options = {}) {
59
+ const image = input instanceof Uint32Array ? input : input.image;
60
+ const src = readFloatGrid(image);
61
+ const codec = mode === "fp4" ? VDB_FP4_LEAF_CODEC
62
+ : mode === "fp8" ? VDB_FP8_LEAF_CODEC
63
+ : mode === "fp16" ? VDB_FP16_LEAF_CODEC
64
+ : mode === "half" ? VDB_HALF_LEAF_CODEC
65
+ : mode === "float" ? VDB_FLOAT_LEAF_CODEC
66
+ : mode === "fpn" ? vdbMakeFpNLeafCodec(tolerance)
67
+ : badMode(mode);
68
+ return vdbBuildFromLeavesDetailed(src.leaves, codec, {
69
+ voxelSize: src.voxelSize,
70
+ worldOrigin: src.translation,
71
+ background: src.background,
72
+ gridName: src.gridName,
73
+ gridClass: src.gridClassId === 1 ? "LevelSet" : src.gridClassId === 2 ? "FogVolume" : "Unknown",
74
+ tiles: src.tiles,
75
+ collapse: options.collapse === true,
76
+ });
77
+ }
78
+ function badMode(mode) {
79
+ throw new VDBToolsError("VDB_BAD_OPTION", `quantize: mode must be 'fp4', 'fp8', 'fp16', 'fpn', 'half' or 'float', got ${JSON.stringify(mode)}`);
80
+ }
81
+ /**
82
+ * Re-encodes a Float or Half grid image (same type) with uniform leaves and
83
+ * nodes collapsed into tiles (OpenVDB `prune`, tolerance 0; K4.6; Half since
84
+ * K7.H1). Values read back identically; see `tree.ts` for the rules.
85
+ */
86
+ export function vdbCollapseGrid(input) {
87
+ const image = input instanceof Uint32Array ? input : input.image;
88
+ const src = readFloatGrid(image, "vdbCollapseGrid");
89
+ return vdbBuildFromLeavesDetailed(src.leaves, src.half ? VDB_HALF_LEAF_CODEC : VDB_FLOAT_LEAF_CODEC, {
90
+ voxelSize: src.voxelSize,
91
+ worldOrigin: src.translation,
92
+ background: src.background,
93
+ gridName: src.gridName,
94
+ gridClass: src.gridClassId === 1 ? "LevelSet" : src.gridClassId === 2 ? "FogVolume" : "Unknown",
95
+ tiles: src.tiles,
96
+ collapse: true,
97
+ });
98
+ }
99
+ const FLOAT_SOURCE = { L: FLOAT_LAYOUT, read: (v, o) => v.getFloat32(o, true), leafStride: 4 };
100
+ const HALF_SOURCE = { L: HALF_LAYOUT, read: (v, o) => vdbHalfToFloat(v.getUint16(o, true)), leafStride: 2 };
101
+ function floorDiv(v, block) {
102
+ return Math.floor(v / block) * block;
103
+ }
104
+ function readI64(view, off) {
105
+ return Number(view.getBigInt64(off, true));
106
+ }
107
+ function maskBit(view, maskBase, n) {
108
+ return ((view.getUint32(maskBase + 4 * (n >>> 5), true) >>> (n & 31)) & 1) !== 0;
109
+ }
110
+ /**
111
+ * Reads a Float or Half grid image's transform/background and yields its leaves (Half values widened
112
+ * to f32, which is exact).
113
+ */
114
+ function readFloatGrid(image, caller = "quantize") {
115
+ const view = new DataView(image.buffer, image.byteOffset, image.byteLength);
116
+ const gridType = view.getUint32(GRID_OFF_GRID_TYPE, true);
117
+ if (gridType !== GRID_TYPE_FLOAT && gridType !== GRID_TYPE_HALF) {
118
+ throw new VDBToolsError("VDB_UNSUPPORTED_GRID_TYPE", `${caller}: source grid type ${gridType} is not FLOAT (${GRID_TYPE_FLOAT}) or HALF (${GRID_TYPE_HALF}); ` +
119
+ `only Float and Half grids are re-encoded (quantized leaves would lose precision twice).`);
120
+ }
121
+ const fmt = gridType === GRID_TYPE_HALF ? HALF_SOURCE : FLOAT_SOURCE;
122
+ // All three: a resampled grid can be anisotropic (K4.4), and the Map must survive quantization.
123
+ const voxelSize = [
124
+ view.getFloat64(GRID_OFF_VOXEL_SIZE, true),
125
+ view.getFloat64(GRID_OFF_VOXEL_SIZE + 8, true),
126
+ view.getFloat64(GRID_OFF_VOXEL_SIZE + 16, true),
127
+ ];
128
+ const vecBase = GRID_OFF_MAP + MAP_OFF_VECD;
129
+ const translation = [
130
+ view.getFloat64(vecBase, true),
131
+ view.getFloat64(vecBase + 8, true),
132
+ view.getFloat64(vecBase + 16, true),
133
+ ];
134
+ const gridClassId = view.getUint32(GRID_OFF_GRID_CLASS, true);
135
+ const gridName = readCString(image, GRID_OFF_GRID_NAME);
136
+ const treeOff = GRID_SIZE;
137
+ const rootOff = treeOff + Number(view.getBigUint64(treeOff + TREE_OFF_NODE_OFFSET_ROOT, true));
138
+ // A level set keeps its root background (+band): its inactive tiles carry the sign (K3.7b). Other grids fill
139
+ // with the near-field value (V5).
140
+ const background = gridClassId === 1 ? fmt.read(view, rootOff + fmt.L.rootOffBackground) : effectiveBackground(view, rootOff, fmt);
141
+ const tiles = [];
142
+ collectFloatTiles(view, rootOff, tiles, fmt, background);
143
+ const leaves = traverseFloatLeaves(view, rootOff, fmt);
144
+ return { half: fmt === HALF_SOURCE, voxelSize, translation, background, gridName, gridClassId, leaves, tiles };
145
+ }
146
+ /**
147
+ * The value inactive regions near the active data read back as. Native grids
148
+ * routinely store a far-field `mBackground` (e.g. a level-set narrow-band 3)
149
+ * that differs from the value written into the *near-field* inactive internal
150
+ * tiles surrounding the active voxels (typically 0). The re-layout emits no
151
+ * inactive tiles, so it fills empty slots with a single background; using the
152
+ * near-field inactive-tile value (the first inactive lower- then upper-tile
153
+ * found) reproduces the source's readback around the data, falling back to the
154
+ * root `mBackground` when the grid has no inactive internal tile at all.
155
+ */
156
+ function effectiveBackground(view, rootOff, fmt) {
157
+ const L = fmt.L;
158
+ const rootBg = fmt.read(view, rootOff + L.rootOffBackground);
159
+ const nTiles = view.getUint32(rootOff + ROOT_OFF_TABLE_SIZE, true);
160
+ let upperInactive;
161
+ for (let t = 0; t < nTiles; t++) {
162
+ const tileOff = rootOff + L.rootSize + t * L.rootTileSize;
163
+ const child = readI64(view, tileOff + ROOT_TILE_OFF_CHILD);
164
+ if (child === 0)
165
+ continue;
166
+ const upperOff = rootOff + child;
167
+ for (let n = 0; n < UPPER_TABLE_COUNT; n++) {
168
+ const slotOff = upperOff + L.upperOffTable + n * L.tableStride;
169
+ if (maskBit(view, upperOff + UPPER_OFF_CHILD_MASK, n)) {
170
+ // Descend one lower node: an inactive lower tile is the near-field value.
171
+ const lowerOff = upperOff + readI64(view, slotOff);
172
+ for (let m = 0; m < LOWER_TABLE_COUNT; m++) {
173
+ const lslot = lowerOff + L.lowerOffTable + m * L.tableStride;
174
+ if (!maskBit(view, lowerOff + LOWER_OFF_CHILD_MASK, m) &&
175
+ !maskBit(view, lowerOff + NODE_OFF_VALUE_MASK, m)) {
176
+ return fmt.read(view, lslot);
177
+ }
178
+ }
179
+ }
180
+ else if (upperInactive === undefined && !maskBit(view, upperOff + NODE_OFF_VALUE_MASK, n)) {
181
+ upperInactive = fmt.read(view, slotOff);
182
+ }
183
+ }
184
+ }
185
+ return upperInactive ?? rootBg;
186
+ }
187
+ /** Child-node offset (relative to `rootOff`) of each root-table entry that has a child. */
188
+ function* rootChildren(view, rootOff) {
189
+ const L = FLOAT_LAYOUT;
190
+ const nTiles = view.getUint32(rootOff + ROOT_OFF_TABLE_SIZE, true);
191
+ for (let t = 0; t < nTiles; t++) {
192
+ const tileOff = rootOff + L.rootSize + t * L.rootTileSize;
193
+ const child = readI64(view, tileOff + ROOT_TILE_OFF_CHILD);
194
+ if (child !== 0)
195
+ yield child;
196
+ }
197
+ }
198
+ /** Index-space min corner of an internal node, from its bbox min. */
199
+ function nodeOrigin(view, nodeOff, dim) {
200
+ return [
201
+ floorDiv(view.getInt32(nodeOff, true), dim),
202
+ floorDiv(view.getInt32(nodeOff + 4, true), dim),
203
+ floorDiv(view.getInt32(nodeOff + 8, true), dim),
204
+ ];
205
+ }
206
+ /**
207
+ * Collects every active tile of a FLOAT image: root tiles (state on, no
208
+ * child), and upper/lower table slots whose value-mask bit is on and child bit
209
+ * off. They are re-emitted as tiles, so the quantized grid keeps the source
210
+ * topology (no expansion into constant leaves).
211
+ */
212
+ function collectFloatTiles(view, rootOff, out, fmt, fill) {
213
+ const L = fmt.L;
214
+ // An inactive tile whose value is not the fill (a level set's interior -band, K4.9) is kept, inactive: dropping it
215
+ // turned a quantized level set's inside into outside (K3.7b).
216
+ const keep = (value, active) => active || value !== fill;
217
+ const nTiles = view.getUint32(rootOff + ROOT_OFF_TABLE_SIZE, true);
218
+ for (let t = 0; t < nTiles; t++) {
219
+ const tileOff = rootOff + L.rootSize + t * L.rootTileSize;
220
+ if (readI64(view, tileOff + ROOT_TILE_OFF_CHILD) !== 0)
221
+ continue;
222
+ const active = view.getUint32(tileOff + ROOT_TILE_OFF_STATE, true) !== 0;
223
+ const value = fmt.read(view, tileOff + L.rootTileOffValue);
224
+ if (!keep(value, active))
225
+ continue;
226
+ const key = view.getBigUint64(tileOff + ROOT_TILE_OFF_KEY, true);
227
+ out.push({ origin: keyToOrigin(key), dim: 4096, value, ...(active ? {} : { active: false }) });
228
+ }
229
+ for (const child of rootChildren(view, rootOff)) {
230
+ const upperOff = rootOff + child;
231
+ const upperOrigin = nodeOrigin(view, upperOff, 4096);
232
+ for (let n = 0; n < UPPER_TABLE_COUNT; n++) {
233
+ const slotOff = upperOff + L.upperOffTable + n * L.tableStride;
234
+ if (maskBit(view, upperOff + UPPER_OFF_CHILD_MASK, n)) {
235
+ const lowerOff = upperOff + readI64(view, slotOff);
236
+ const lowerOrigin = nodeOrigin(view, lowerOff, 128);
237
+ for (let m = 0; m < LOWER_TABLE_COUNT; m++) {
238
+ if (maskBit(view, lowerOff + LOWER_OFF_CHILD_MASK, m))
239
+ continue;
240
+ const active = maskBit(view, lowerOff + NODE_OFF_VALUE_MASK, m);
241
+ const value = fmt.read(view, lowerOff + L.lowerOffTable + m * L.tableStride);
242
+ if (!keep(value, active))
243
+ continue;
244
+ out.push({
245
+ origin: [
246
+ lowerOrigin[0] + (((m >> 8) & 15) << 3),
247
+ lowerOrigin[1] + (((m >> 4) & 15) << 3),
248
+ lowerOrigin[2] + ((m & 15) << 3),
249
+ ],
250
+ dim: 8,
251
+ value,
252
+ ...(active ? {} : { active: false }),
253
+ });
254
+ }
255
+ }
256
+ else {
257
+ const active = maskBit(view, upperOff + NODE_OFF_VALUE_MASK, n);
258
+ const value = fmt.read(view, slotOff);
259
+ if (!keep(value, active))
260
+ continue;
261
+ out.push({
262
+ origin: [
263
+ upperOrigin[0] + (((n >> 10) & 31) << 7),
264
+ upperOrigin[1] + (((n >> 5) & 31) << 7),
265
+ upperOrigin[2] + ((n & 31) << 7),
266
+ ],
267
+ dim: 128,
268
+ value,
269
+ ...(active ? {} : { active: false }),
270
+ });
271
+ }
272
+ }
273
+ }
274
+ }
275
+ /**
276
+ * Inverse of `coordToKey`: each 21-bit field holds `u32(c) >>> 12`, so
277
+ * shifting it back up by 12 in 32-bit arithmetic restores the signed,
278
+ * 4096-aligned coordinate.
279
+ */
280
+ function keyToOrigin(key) {
281
+ const axis = (shift) => Number((key >> shift) & 0xfffffn) << 12;
282
+ return [axis(42n), axis(21n), axis(0n)];
283
+ }
284
+ /** Walks root -> upper -> lower -> leaf, yielding one {@link LeafInput} per real leaf. */
285
+ function* traverseFloatLeaves(view, rootOff, fmt) {
286
+ for (const child of rootChildren(view, rootOff)) {
287
+ const upperOff = rootOff + child;
288
+ for (let n = 0; n < UPPER_TABLE_COUNT; n++) {
289
+ if (!maskBit(view, upperOff + UPPER_OFF_CHILD_MASK, n))
290
+ continue;
291
+ const slotOff = upperOff + fmt.L.upperOffTable + n * fmt.L.tableStride;
292
+ yield* traverseLower(view, upperOff + readI64(view, slotOff), fmt);
293
+ }
294
+ }
295
+ }
296
+ function* traverseLower(view, lowerOff, fmt) {
297
+ const L = fmt.L;
298
+ const lowerOrigin = nodeOrigin(view, lowerOff, 128);
299
+ for (let n = 0; n < LOWER_TABLE_COUNT; n++) {
300
+ if (!maskBit(view, lowerOff + LOWER_OFF_CHILD_MASK, n))
301
+ continue;
302
+ const slotOff = lowerOff + L.lowerOffTable + n * L.tableStride;
303
+ const origin = [
304
+ lowerOrigin[0] + (((n >> 8) & 15) << 3),
305
+ lowerOrigin[1] + (((n >> 4) & 15) << 3),
306
+ lowerOrigin[2] + ((n & 15) << 3),
307
+ ];
308
+ yield readLeaf(view, lowerOff + readI64(view, slotOff), origin, fmt);
309
+ }
310
+ }
311
+ /** Reads one real Float or Half leaf (512 values + value mask) at `leafOff`. */
312
+ function readLeaf(view, leafOff, origin, fmt) {
313
+ const tableOff = fmt.L.leafOffTable;
314
+ const valueMask = new Uint32Array(16);
315
+ for (let w = 0; w < 16; w++)
316
+ valueMask[w] = view.getUint32(leafOff + LEAF_OFF_VALUE_MASK + w * 4, true);
317
+ const values = new Float32Array(LEAF_TABLE_COUNT);
318
+ for (let n = 0; n < LEAF_TABLE_COUNT; n++)
319
+ values[n] = fmt.read(view, leafOff + tableOff + n * fmt.leafStride);
320
+ return { origin, values, valueMask };
321
+ }
322
+ function readCString(image, byteOffset) {
323
+ const bytes = new Uint8Array(image.buffer, image.byteOffset + byteOffset);
324
+ let end = 0;
325
+ while (end < 256 && bytes[end] !== 0)
326
+ end++;
327
+ return new TextDecoder().decode(bytes.subarray(0, end));
328
+ }
329
+ //# sourceMappingURL=quantize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quantize.js","sourceRoot":"","sources":["../../../src/tools/nanovdb/quantize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EAClB,YAAY,EACZ,mBAAmB,EACnB,SAAS,EACT,eAAe,EACf,cAAc,EACd,WAAW,EAEX,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,EACjB,YAAY,EACZ,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,EACnB,yBAAyB,EACzB,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,kB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AACvC,CAAC;AAED,SAAS,WAAW,CAAC,KAAkB,EAAE,UAAkB;IACzD,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,GAAG,UAAU,CAAC,CAAC;IAC1E,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,OAAO,GAAG,GAAG,GAAG,IAAI,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC;QAAE,GAAG,EAAE,CAAC;IAC5C,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;AAC1D,CAAC","sourcesContent":["/**\n * quantize.ts — re-encode a Float or Half NanoVDB grid image as Fp4, Fp8, Fp16, FpN, Half or Float.\n *\n * Quantization is a leaf-value-representation change only: topology, masks,\n * internal-node tables/stats, GridData and the transform are unchanged. So\n * `quantize` reads the source FLOAT image's leaves (each: 8-aligned origin,\n * all 512 values, value mask), its active tiles (root, upper, lower; kept as\n * tiles since K4.1 — tile values stay plain f32 in Fp8/FpN grids) and its\n * GridData transform/background, then re-runs the leaf-iterator build path\n * ({@link vdbBuildFromLeavesDetailed}) with the chosen quantizing {@link VDBLeafCodec}. The result satisfies the repo's proven decoders\n * (`read-value.ts` `leafFp*ReadFloat`, `pnanovdb.wgsl`).\n *\n * - `fp4` / `fp8` / `fp16` — fixed 4/8/16-bit codes; per-leaf quantum = (max-min)/(2^bits-1).\n * The CreateNanoGrid rules Fp8 uses (min/quantum over all 512 values, round-to-nearest, no\n * dither); `tolerance` is ignored. No native Fp4/Fp16 fixtures exist, so these are verified\n * by decoder round-trip and GPU parity, not byte-compared to `nanovdb_convert`.\n * - `fpn` — per-leaf variable bit-width, smallest of 1/2/4/8/16 bits whose\n * dequantized values stay within `tolerance` (default: native's FogVolume 0.01).\n * - `half` (K7.H) — NanoVDB `GridType::Half` (NanoVDB 13.2): every value (leaf\n * voxels, tiles, background) becomes the nearest IEEE binary16 (round to\n * nearest even, `|v| > 65504` to infinity; NanoVDB `math::FloatToHalf`), as\n * `tools::createNanoGrid<FloatGrid, Half>` writes it; min/max stats are\n * binary16, ave/stddev f32 over the stored halves. Relative error <= 2^-11 in\n * the normal range (6.1e-5 to 65504); absolute <= 2^-25 below it. `tolerance`\n * is ignored. Cross-checked against native NanoVDB v14.0.0\n * (`docker/fixture-bake/bake_half.cpp`, `test/tools/half-native.test.ts`).\n *\n * - `float` (K7.H1) — plain f32 leaves: widens a Half grid exactly (Half ->\n * Float -> Half is the identity), or re-lays out a Float grid.\n *\n * Sources are Float or Half grids (K7.H1; Half values widen to f32 exactly);\n * quantized sources throw, since re-quantizing loses precision twice.\n */\n\nimport { VDBToolsError } from \"../errors.js\";\nimport {\n FLOAT_LAYOUT,\n GRID_OFF_GRID_CLASS,\n GRID_OFF_GRID_NAME,\n GRID_OFF_GRID_TYPE,\n GRID_OFF_MAP,\n GRID_OFF_VOXEL_SIZE,\n GRID_SIZE,\n GRID_TYPE_FLOAT,\n GRID_TYPE_HALF,\n HALF_LAYOUT,\n type GridTypeLayout,\n LEAF_OFF_VALUE_MASK,\n LEAF_TABLE_COUNT,\n LOWER_OFF_CHILD_MASK,\n LOWER_TABLE_COUNT,\n MAP_OFF_VECD,\n NODE_OFF_VALUE_MASK,\n ROOT_OFF_TABLE_SIZE,\n ROOT_TILE_OFF_CHILD,\n ROOT_TILE_OFF_KEY,\n ROOT_TILE_OFF_STATE,\n TREE_OFF_NODE_OFFSET_ROOT,\n UPPER_OFF_CHILD_MASK,\n UPPER_TABLE_COUNT,\n} from \"./bytes.js\";\nimport {\n VDB_FLOAT_LEAF_CODEC,\n VDB_FP4_LEAF_CODEC,\n VDB_FP8_LEAF_CODEC,\n VDB_FP16_LEAF_CODEC,\n VDB_HALF_LEAF_CODEC,\n vdbMakeFpNLeafCodec,\n type VDBLeafCodec,\n} from \"./leaf-codec.js\";\nimport { vdbHalfToFloat } from \"./half.js\";\nimport { vdbBuildFromLeavesDetailed, type VDBBuiltGrid } from \"./serialize.js\";\nimport type { LeafInput, TileInput } from \"./tree.js\";\n\n/**\n * Target encoding of {@link vdbQuantize}: fixed 4, 8 or 16-bit codes, FpN (bit-width chosen per leaf by tolerance),\n * Half (raw IEEE binary16, K7.H) or Float (f32; widens a Half source exactly, K7.H1).\n */\nexport type VDBQuantizeMode = \"fp4\" | \"fp8\" | \"fp16\" | \"fpn\" | \"half\" | \"float\";\n\n/** Options of {@link vdbQuantize}. */\nexport interface VDBQuantizeOptions {\n /**\n * Also collapse uniform leaves and nodes of the source into tiles (OpenVDB\n * `prune`, tolerance 0; K4.6). Default false: quantizing keeps the source\n * topology, so a native FLOAT image quantizes to native's Fp8/FpN layout.\n */\n collapse?: boolean;\n}\n\n/**\n * Re-encodes a Float or Half grid image (or built grid) as Fp4/Fp8/Fp16/FpN, Half or Float. Returns a new image.\n *\n * @param input A Float or Half grid image, or a built grid.\n * @param mode Target encoding.\n * @param tolerance Absolute error bound for `'fpn'` (leaf bit-width is chosen to meet it); ignored by the other modes.\n * @param options Topology options (leaf collapsing).\n */\nexport function vdbQuantize(\n input: Uint32Array | VDBBuiltGrid,\n mode: VDBQuantizeMode,\n tolerance?: number,\n options: VDBQuantizeOptions = {},\n): Uint32Array {\n return vdbQuantizeDetailed(input, mode, tolerance, options).image;\n}\n\n/**\n * As {@link vdbQuantize}, but returns the computed metadata alongside the image.\n *\n * @param input A Float or Half grid image, or a built grid.\n * @param mode Target encoding.\n * @param tolerance Absolute error bound for `'fpn'`; ignored by the fixed-width modes.\n * @param options Topology options (leaf collapsing).\n */\nexport function vdbQuantizeDetailed(\n input: Uint32Array | VDBBuiltGrid,\n mode: VDBQuantizeMode,\n tolerance?: number,\n options: VDBQuantizeOptions = {},\n): VDBBuiltGrid {\n const image = input instanceof Uint32Array ? input : input.image;\n const src = readFloatGrid(image);\n const codec: VDBLeafCodec =\n mode === \"fp4\" ? VDB_FP4_LEAF_CODEC\n : mode === \"fp8\" ? VDB_FP8_LEAF_CODEC\n : mode === \"fp16\" ? VDB_FP16_LEAF_CODEC\n : mode === \"half\" ? VDB_HALF_LEAF_CODEC\n : mode === \"float\" ? VDB_FLOAT_LEAF_CODEC\n : mode === \"fpn\" ? vdbMakeFpNLeafCodec(tolerance)\n : badMode(mode);\n return vdbBuildFromLeavesDetailed(src.leaves, codec, {\n voxelSize: src.voxelSize,\n worldOrigin: src.translation,\n background: src.background,\n gridName: src.gridName,\n gridClass:\n src.gridClassId === 1 ? \"LevelSet\" : src.gridClassId === 2 ? \"FogVolume\" : \"Unknown\",\n tiles: src.tiles,\n collapse: options.collapse === true,\n });\n}\n\nfunction badMode(mode: unknown): never {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", `quantize: mode must be 'fp4', 'fp8', 'fp16', 'fpn', 'half' or 'float', got ${JSON.stringify(mode)}`);\n}\n\n/**\n * Re-encodes a Float or Half grid image (same type) with uniform leaves and\n * nodes collapsed into tiles (OpenVDB `prune`, tolerance 0; K4.6; Half since\n * K7.H1). Values read back identically; see `tree.ts` for the rules.\n */\nexport function vdbCollapseGrid(input: Uint32Array | VDBBuiltGrid): VDBBuiltGrid {\n const image = input instanceof Uint32Array ? input : input.image;\n const src = readFloatGrid(image, \"vdbCollapseGrid\");\n return vdbBuildFromLeavesDetailed(src.leaves, src.half ? VDB_HALF_LEAF_CODEC : VDB_FLOAT_LEAF_CODEC, {\n voxelSize: src.voxelSize,\n worldOrigin: src.translation,\n background: src.background,\n gridName: src.gridName,\n gridClass: src.gridClassId === 1 ? \"LevelSet\" : src.gridClassId === 2 ? \"FogVolume\" : \"Unknown\",\n tiles: src.tiles,\n collapse: true,\n });\n}\n\n/** How a source grid's values are stored: f32 (Float) or binary16 (Half, K7.H1). */\ninterface SourceFormat {\n L: GridTypeLayout;\n /** Reads one value (a leaf value, a tile, the background) at a byte offset. */\n read(view: DataView, off: number): number;\n /** Bytes per leaf value. */\n leafStride: number;\n}\nconst FLOAT_SOURCE: SourceFormat = { L: FLOAT_LAYOUT, read: (v, o) => v.getFloat32(o, true), leafStride: 4 };\nconst HALF_SOURCE: SourceFormat = { L: HALF_LAYOUT, read: (v, o) => vdbHalfToFloat(v.getUint16(o, true)), leafStride: 2 };\n\ninterface FloatGridView {\n /** The source is a Half grid (its values widened to f32, exactly). */\n half: boolean;\n voxelSize: [number, number, number];\n translation: [number, number, number];\n background: number;\n gridName: string;\n gridClassId: number;\n leaves: Iterable<LeafInput>;\n tiles: TileInput[];\n}\n\nfunction floorDiv(v: number, block: number): number {\n return Math.floor(v / block) * block;\n}\n\nfunction readI64(view: DataView, off: number): number {\n return Number(view.getBigInt64(off, true));\n}\n\nfunction maskBit(view: DataView, maskBase: number, n: number): boolean {\n return ((view.getUint32(maskBase + 4 * (n >>> 5), true) >>> (n & 31)) & 1) !== 0;\n}\n\n/**\n * Reads a Float or Half grid image's transform/background and yields its leaves (Half values widened\n * to f32, which is exact).\n */\nfunction readFloatGrid(image: Uint32Array, caller = \"quantize\"): FloatGridView {\n const view = new DataView(image.buffer, image.byteOffset, image.byteLength);\n const gridType = view.getUint32(GRID_OFF_GRID_TYPE, true);\n if (gridType !== GRID_TYPE_FLOAT && gridType !== GRID_TYPE_HALF) {\n throw new VDBToolsError(\"VDB_UNSUPPORTED_GRID_TYPE\",\n `${caller}: source grid type ${gridType} is not FLOAT (${GRID_TYPE_FLOAT}) or HALF (${GRID_TYPE_HALF}); ` +\n `only Float and Half grids are re-encoded (quantized leaves would lose precision twice).`,\n );\n }\n const fmt = gridType === GRID_TYPE_HALF ? HALF_SOURCE : FLOAT_SOURCE;\n // All three: a resampled grid can be anisotropic (K4.4), and the Map must survive quantization.\n const voxelSize: [number, number, number] = [\n view.getFloat64(GRID_OFF_VOXEL_SIZE, true),\n view.getFloat64(GRID_OFF_VOXEL_SIZE + 8, true),\n view.getFloat64(GRID_OFF_VOXEL_SIZE + 16, true),\n ];\n const vecBase = GRID_OFF_MAP + MAP_OFF_VECD;\n const translation: [number, number, number] = [\n view.getFloat64(vecBase, true),\n view.getFloat64(vecBase + 8, true),\n view.getFloat64(vecBase + 16, true),\n ];\n const gridClassId = view.getUint32(GRID_OFF_GRID_CLASS, true);\n const gridName = readCString(image, GRID_OFF_GRID_NAME);\n\n const treeOff = GRID_SIZE;\n const rootOff = treeOff + Number(view.getBigUint64(treeOff + TREE_OFF_NODE_OFFSET_ROOT, true));\n // A level set keeps its root background (+band): its inactive tiles carry the sign (K3.7b). Other grids fill\n // with the near-field value (V5).\n const background = gridClassId === 1 ? fmt.read(view, rootOff + fmt.L.rootOffBackground) : effectiveBackground(view, rootOff, fmt);\n\n const tiles: TileInput[] = [];\n collectFloatTiles(view, rootOff, tiles, fmt, background);\n const leaves = traverseFloatLeaves(view, rootOff, fmt);\n return { half: fmt === HALF_SOURCE, voxelSize, translation, background, gridName, gridClassId, leaves, tiles };\n}\n\n/**\n * The value inactive regions near the active data read back as. Native grids\n * routinely store a far-field `mBackground` (e.g. a level-set narrow-band 3)\n * that differs from the value written into the *near-field* inactive internal\n * tiles surrounding the active voxels (typically 0). The re-layout emits no\n * inactive tiles, so it fills empty slots with a single background; using the\n * near-field inactive-tile value (the first inactive lower- then upper-tile\n * found) reproduces the source's readback around the data, falling back to the\n * root `mBackground` when the grid has no inactive internal tile at all.\n */\nfunction effectiveBackground(view: DataView, rootOff: number, fmt: SourceFormat): number {\n const L = fmt.L;\n const rootBg = fmt.read(view, rootOff + L.rootOffBackground);\n const nTiles = view.getUint32(rootOff + ROOT_OFF_TABLE_SIZE, true);\n let upperInactive: number | undefined;\n for (let t = 0; t < nTiles; t++) {\n const tileOff = rootOff + L.rootSize + t * L.rootTileSize;\n const child = readI64(view, tileOff + ROOT_TILE_OFF_CHILD);\n if (child === 0) continue;\n const upperOff = rootOff + child;\n for (let n = 0; n < UPPER_TABLE_COUNT; n++) {\n const slotOff = upperOff + L.upperOffTable + n * L.tableStride;\n if (maskBit(view, upperOff + UPPER_OFF_CHILD_MASK, n)) {\n // Descend one lower node: an inactive lower tile is the near-field value.\n const lowerOff = upperOff + readI64(view, slotOff);\n for (let m = 0; m < LOWER_TABLE_COUNT; m++) {\n const lslot = lowerOff + L.lowerOffTable + m * L.tableStride;\n if (\n !maskBit(view, lowerOff + LOWER_OFF_CHILD_MASK, m) &&\n !maskBit(view, lowerOff + NODE_OFF_VALUE_MASK, m)\n ) {\n return fmt.read(view, lslot);\n }\n }\n } else if (upperInactive === undefined && !maskBit(view, upperOff + NODE_OFF_VALUE_MASK, n)) {\n upperInactive = fmt.read(view, slotOff);\n }\n }\n }\n return upperInactive ?? rootBg;\n}\n\n/** Child-node offset (relative to `rootOff`) of each root-table entry that has a child. */\nfunction* rootChildren(view: DataView, rootOff: number): Iterable<number> {\n const L = FLOAT_LAYOUT;\n const nTiles = view.getUint32(rootOff + ROOT_OFF_TABLE_SIZE, true);\n for (let t = 0; t < nTiles; t++) {\n const tileOff = rootOff + L.rootSize + t * L.rootTileSize;\n const child = readI64(view, tileOff + ROOT_TILE_OFF_CHILD);\n if (child !== 0) yield child;\n }\n}\n\n/** Index-space min corner of an internal node, from its bbox min. */\nfunction nodeOrigin(view: DataView, nodeOff: number, dim: number): [number, number, number] {\n return [\n floorDiv(view.getInt32(nodeOff, true), dim),\n floorDiv(view.getInt32(nodeOff + 4, true), dim),\n floorDiv(view.getInt32(nodeOff + 8, true), dim),\n ];\n}\n\n/**\n * Collects every active tile of a FLOAT image: root tiles (state on, no\n * child), and upper/lower table slots whose value-mask bit is on and child bit\n * off. They are re-emitted as tiles, so the quantized grid keeps the source\n * topology (no expansion into constant leaves).\n */\nfunction collectFloatTiles(view: DataView, rootOff: number, out: TileInput[], fmt: SourceFormat, fill: number): void {\n const L = fmt.L;\n // An inactive tile whose value is not the fill (a level set's interior -band, K4.9) is kept, inactive: dropping it\n // turned a quantized level set's inside into outside (K3.7b).\n const keep = (value: number, active: boolean): boolean => active || value !== fill;\n const nTiles = view.getUint32(rootOff + ROOT_OFF_TABLE_SIZE, true);\n for (let t = 0; t < nTiles; t++) {\n const tileOff = rootOff + L.rootSize + t * L.rootTileSize;\n if (readI64(view, tileOff + ROOT_TILE_OFF_CHILD) !== 0) continue;\n const active = view.getUint32(tileOff + ROOT_TILE_OFF_STATE, true) !== 0;\n const value = fmt.read(view, tileOff + L.rootTileOffValue);\n if (!keep(value, active)) continue;\n const key = view.getBigUint64(tileOff + ROOT_TILE_OFF_KEY, true);\n out.push({ origin: keyToOrigin(key), dim: 4096, value, ...(active ? {} : { active: false }) });\n }\n for (const child of rootChildren(view, rootOff)) {\n const upperOff = rootOff + child;\n const upperOrigin = nodeOrigin(view, upperOff, 4096);\n for (let n = 0; n < UPPER_TABLE_COUNT; n++) {\n const slotOff = upperOff + L.upperOffTable + n * L.tableStride;\n if (maskBit(view, upperOff + UPPER_OFF_CHILD_MASK, n)) {\n const lowerOff = upperOff + readI64(view, slotOff);\n const lowerOrigin = nodeOrigin(view, lowerOff, 128);\n for (let m = 0; m < LOWER_TABLE_COUNT; m++) {\n if (maskBit(view, lowerOff + LOWER_OFF_CHILD_MASK, m)) continue;\n const active = maskBit(view, lowerOff + NODE_OFF_VALUE_MASK, m);\n const value = fmt.read(view, lowerOff + L.lowerOffTable + m * L.tableStride);\n if (!keep(value, active)) continue;\n out.push({\n origin: [\n lowerOrigin[0] + (((m >> 8) & 15) << 3),\n lowerOrigin[1] + (((m >> 4) & 15) << 3),\n lowerOrigin[2] + ((m & 15) << 3),\n ],\n dim: 8,\n value,\n ...(active ? {} : { active: false }),\n });\n }\n } else {\n const active = maskBit(view, upperOff + NODE_OFF_VALUE_MASK, n);\n const value = fmt.read(view, slotOff);\n if (!keep(value, active)) continue;\n out.push({\n origin: [\n upperOrigin[0] + (((n >> 10) & 31) << 7),\n upperOrigin[1] + (((n >> 5) & 31) << 7),\n upperOrigin[2] + ((n & 31) << 7),\n ],\n dim: 128,\n value,\n ...(active ? {} : { active: false }),\n });\n }\n }\n }\n}\n\n/**\n * Inverse of `coordToKey`: each 21-bit field holds `u32(c) >>> 12`, so\n * shifting it back up by 12 in 32-bit arithmetic restores the signed,\n * 4096-aligned coordinate.\n */\nfunction keyToOrigin(key: bigint): [number, number, number] {\n const axis = (shift: bigint): number => Number((key >> shift) & 0xfffffn) << 12;\n return [axis(42n), axis(21n), axis(0n)];\n}\n\n/** Walks root -> upper -> lower -> leaf, yielding one {@link LeafInput} per real leaf. */\nfunction* traverseFloatLeaves(view: DataView, rootOff: number, fmt: SourceFormat): Iterable<LeafInput> {\n for (const child of rootChildren(view, rootOff)) {\n const upperOff = rootOff + child;\n for (let n = 0; n < UPPER_TABLE_COUNT; n++) {\n if (!maskBit(view, upperOff + UPPER_OFF_CHILD_MASK, n)) continue;\n const slotOff = upperOff + fmt.L.upperOffTable + n * fmt.L.tableStride;\n yield* traverseLower(view, upperOff + readI64(view, slotOff), fmt);\n }\n }\n}\n\nfunction* traverseLower(view: DataView, lowerOff: number, fmt: SourceFormat): Iterable<LeafInput> {\n const L = fmt.L;\n const lowerOrigin = nodeOrigin(view, lowerOff, 128);\n for (let n = 0; n < LOWER_TABLE_COUNT; n++) {\n if (!maskBit(view, lowerOff + LOWER_OFF_CHILD_MASK, n)) continue;\n const slotOff = lowerOff + L.lowerOffTable + n * L.tableStride;\n const origin: [number, number, number] = [\n lowerOrigin[0] + (((n >> 8) & 15) << 3),\n lowerOrigin[1] + (((n >> 4) & 15) << 3),\n lowerOrigin[2] + ((n & 15) << 3),\n ];\n yield readLeaf(view, lowerOff + readI64(view, slotOff), origin, fmt);\n }\n}\n\n/** Reads one real Float or Half leaf (512 values + value mask) at `leafOff`. */\nfunction readLeaf(view: DataView, leafOff: number, origin: [number, number, number], fmt: SourceFormat): LeafInput {\n const tableOff = fmt.L.leafOffTable;\n const valueMask = new Uint32Array(16);\n for (let w = 0; w < 16; w++) valueMask[w] = view.getUint32(leafOff + LEAF_OFF_VALUE_MASK + w * 4, true);\n const values = new Float32Array(LEAF_TABLE_COUNT);\n for (let n = 0; n < LEAF_TABLE_COUNT; n++) values[n] = fmt.read(view, leafOff + tableOff + n * fmt.leafStride);\n return { origin, values, valueMask };\n}\n\nfunction readCString(image: Uint32Array, byteOffset: number): string {\n const bytes = new Uint8Array(image.buffer, image.byteOffset + byteOffset);\n let end = 0;\n while (end < 256 && bytes[end] !== 0) end++;\n return new TextDecoder().decode(bytes.subarray(0, end));\n}\n"]}
@@ -0,0 +1,177 @@
1
+ /**
2
+ * resample.ts — resample a sparse grid to a new resolution (K4.4) and build a
3
+ * NanoVDB FLOAT image from it, optionally quantized to Fp8/FpN.
4
+ *
5
+ * ## Conventions
6
+ *
7
+ * Voxels are centred at integer index coordinates, the convention of the CPU
8
+ * oracle's `readValue`/`vdbSampleTrilinearCpu` (and the WGSL sampler), and of
9
+ * mjurczyk's `.wvdb` bake (`Math.round` in index space). Voxel `i` therefore
10
+ * covers the index interval `[i - 0.5, i + 0.5]`.
11
+ *
12
+ * - **Box.** A world-space box `[min, max]`. Default: the cell box of the
13
+ * source's active voxels, `[imin - 0.5, imax + 0.5]` in source index space,
14
+ * mapped to world. Pass `bbox` for a shared box (a sequence) or to reproduce
15
+ * a `.wvdb` bake (his box is the voxel-centre box, `wvdbSourceFromVdbGrid(g).bbox`).
16
+ * - **Target lattice.** `dims` voxels per axis with voxel size `vs` per axis;
17
+ * target voxel `j` is centred at `min + ((j + 0.5) / dims) * (dims * vs)`, the
18
+ * arithmetic of his `forEachTexel`. The output Map is `world = vs * ijk + t`
19
+ * with `t = min + vs / 2`, so the target index box is `[0, dims - 1]`.
20
+ * - **Resolution.** Exactly one of `resolution` (voxels on the longest box side,
21
+ * uniform voxels), `voxelSize` (number: uniform; `[x, y, z]`: anisotropic) or
22
+ * `dimensions` (voxels per axis; voxel size = box / dims, anisotropic unless
23
+ * the box is proportional). With none, the source voxel size (an identity
24
+ * resample). With `resolution` or `voxelSize`, `dims = ceil(side / vs)` and the
25
+ * box grows at its max side to a whole number of voxels; with `dimensions`
26
+ * the box is kept exactly.
27
+ *
28
+ * ## Filters
29
+ *
30
+ * The map between target and source index space is separable (both maps are
31
+ * axis-aligned), so every filter is a per-axis weight table applied as three
32
+ * 1D passes over a gathered block of source voxels.
33
+ *
34
+ * - `'point'`: the nearest source voxel (`Math.round`), no prefilter. Same
35
+ * positions and arithmetic as the `.wvdb` bake; aliases when downsampling.
36
+ * - `'box'` (default): the area-weighted average of the source voxels the
37
+ * target voxel's cell overlaps (inactive voxels count with their stored
38
+ * value, normally the background). It is the right default for
39
+ * downsampling: it is the integral of the source field over the target
40
+ * voxel, so mass (density times volume) is conserved, the coarse grid is the
41
+ * source seen at the coarse scale, and thin features fade instead of
42
+ * flickering in or out with the sampling phase. A downsample by 2 on an
43
+ * aligned box is the exact 2x2x2 mean.
44
+ * - `'trilinear'`: the trilinear interpolation of the source at the target
45
+ * voxel centre (`vdbSampleTrilinearCpu`). Smooth for upsampling and small ratios;
46
+ * aliases like `'point'` at large downsampling ratios.
47
+ *
48
+ * ## Sparsity
49
+ *
50
+ * Only target leaves whose filter footprint overlaps a source leaf or active
51
+ * tile are visited (empty space costs nothing), and a target voxel is active
52
+ * only when its footprint touches an active source voxel and, given `cutoff`,
53
+ * `|value - background| > cutoff`. Leaves left with no active voxel are dropped.
54
+ * Inactive voxels inside an emitted leaf keep their filtered value (the field a
55
+ * texture sampler would see).
56
+ */
57
+ import type { VdbFile, VdbGrid } from "../vdb/types.js";
58
+ import { type VDBQuantizeMode } from "./quantize.js";
59
+ import { type VDBBuiltGrid } from "./serialize.js";
60
+ type Vec3 = [number, number, number];
61
+ /** Resampling filter: nearest source voxel (`point`), mean over the target footprint (`box`), or trilinear. */
62
+ export type VDBResampleFilter = "point" | "box" | "trilinear";
63
+ /** A NanoVDB FLOAT/Fp8/FpN grid image, a parsed `.vdb` float grid, or a parsed `.vdb` file. */
64
+ export type VDBResampleSource = Uint32Array | VdbGrid | VdbFile;
65
+ /** Options of {@link vdbResampleGrid}: set one of `resolution`, `voxelSize` or `dimensions`. */
66
+ export interface VDBResampleOptions {
67
+ /** Voxels on the longest side of the box; uniform voxels. */
68
+ resolution?: number;
69
+ /** Target voxel size in world units: uniform, or `[x, y, z]` (anisotropic). */
70
+ voxelSize?: number | Vec3;
71
+ /** Target voxels per axis; voxel size = box size / dims per axis. */
72
+ dimensions?: Vec3;
73
+ /** Default `'box'`. */
74
+ filter?: VDBResampleFilter;
75
+ /** World box `[min, max]`. Default: the source's active cell box. */
76
+ bbox?: [Vec3, Vec3];
77
+ /**
78
+ * Keep a target voxel active only if `|value - background| > cutoff` (as
79
+ * well as touching an active source voxel). Default: no value test.
80
+ */
81
+ cutoff?: number;
82
+ /** Quantize the result (via `quantize`). Default: FLOAT. */
83
+ quantize?: VDBQuantizeMode;
84
+ /** FpN tolerance (`quantize`'s, default 0.01). */
85
+ tolerance?: number;
86
+ /** Which grid of a `VdbFile` to resample. Default: the first float grid. */
87
+ sourceGridName?: string;
88
+ /** Output grid name. Default: the source grid's name. */
89
+ gridName?: string;
90
+ /** Output background. Default: the source's root background. */
91
+ background?: number;
92
+ /**
93
+ * Collapse uniform target leaves and nodes into tiles (OpenVDB `prune`,
94
+ * tolerance 0; K4.6), before any quantization. Default true: a resample is a
95
+ * new build with no native topology to keep, and a uniform interior (a
96
+ * source tile, or a saturated core) costs one tile instead of leaves.
97
+ */
98
+ collapse?: boolean;
99
+ }
100
+ /** A resampled grid: the built grid plus the resample's own parameters. */
101
+ export interface VDBResampledGrid extends VDBBuiltGrid {
102
+ /** Target voxels per axis (the index box is `[0, dims - 1]`). */
103
+ dimensions: Vec3;
104
+ /** The world box that was resampled (grown to whole voxels for `resolution`/`voxelSize`). */
105
+ bbox: [Vec3, Vec3];
106
+ /** The filter that was used. */
107
+ filter: VDBResampleFilter;
108
+ /** Source voxel size per axis. */
109
+ sourceVoxelSize: Vec3;
110
+ }
111
+ /**
112
+ * Resamples a sparse grid to a new resolution over a world box and builds a
113
+ * NanoVDB FLOAT image (optionally quantized to Fp8/FpN). See the module doc for
114
+ * the conventions, filters and sparsity rule.
115
+ *
116
+ * @param source A FLOAT/Fp8/FpN grid image, a parsed `.vdb` float grid, or a parsed `.vdb` file.
117
+ * @param options Target resolution, filter, box and encoding.
118
+ */
119
+ export declare function vdbResampleGrid(source: VDBResampleSource, options?: VDBResampleOptions): VDBResampledGrid;
120
+ /** Options of {@link vdbResampleDense}. */
121
+ export interface VDBResampleDenseOptions {
122
+ /** World box `[min, max]`: target voxel `j` is centred at `min + ((j + 0.5) / dims) * (max - min)`. */
123
+ bbox: [Vec3, Vec3];
124
+ /** Target voxels per axis. */
125
+ dimensions: Vec3;
126
+ /** Default `'box'`. */
127
+ filter?: VDBResampleFilter;
128
+ /** Which grid of a `VdbFile`. Default: the first float grid. */
129
+ sourceGridName?: string;
130
+ }
131
+ /**
132
+ * {@link vdbResampleGrid}'s filters onto a dense lattice (the `.wvdb` bake's,
133
+ * K4.13): `values` x fastest (`x + y*X + z*X*Y`), `active` 1 where the target
134
+ * voxel's footprint touches an active source voxel. Voxels in no emitted leaf
135
+ * (the footprint touches no active source voxel) hold the source background.
136
+ * Unlike `vdbResampleGrid`, the box may have zero size on an axis (one voxel
137
+ * thick); that axis samples the nearest source voxel.
138
+ *
139
+ * @param source A FLOAT/Fp8/FpN grid image, a parsed `.vdb` float grid, or a parsed `.vdb` file.
140
+ * @param options The world box, target dimensions and filter.
141
+ */
142
+ export declare function vdbResampleDense(source: VDBResampleSource, options: VDBResampleDenseOptions): {
143
+ values: Float32Array;
144
+ active: Uint8Array;
145
+ background: number;
146
+ };
147
+ /** Options of {@link vdbResampleError}. */
148
+ export interface VDBResampleErrorOptions {
149
+ /** Use every `stride`-th active source voxel (leaf order). Default 7, as in the comparison report. */
150
+ stride?: number;
151
+ /** Which grid of a `VdbFile`. Default: the first float grid. */
152
+ sourceGridName?: string;
153
+ }
154
+ /** Result of {@link vdbResampleError}. */
155
+ export interface VDBResampleErrorResult {
156
+ /** Mean |target − source| over the sampled active source voxels. */
157
+ meanAbsError: number;
158
+ /** Mean source value over the same voxels. */
159
+ meanValue: number;
160
+ /** `100 * meanAbsError / meanValue`. */
161
+ percent: number;
162
+ /** Voxels compared. */
163
+ count: number;
164
+ }
165
+ /**
166
+ * The error metric of the mjurczyk comparison (docs/dev/research/INDEX): mean absolute
167
+ * difference over every `stride`-th active source voxel, as a percentage of the
168
+ * mean source value there. The target (any NanoVDB FLOAT/Fp8/FpN image with an
169
+ * axis-aligned Map) is read back with `vdbSampleTrilinearCpu` at each source voxel
170
+ * centre. Active tiles are not sampled (leaves only).
171
+ *
172
+ * @param source The full-resolution source (image, `.vdb` grid or file).
173
+ * @param target The resampled grid image to compare against the source.
174
+ * @param options Sampling stride and source grid name.
175
+ */
176
+ export declare function vdbResampleError(source: VDBResampleSource, target: Uint32Array, options?: VDBResampleErrorOptions): VDBResampleErrorResult;
177
+ export {};