@pmndrs/vdb 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (576) hide show
  1. package/CHANGELOG.md +592 -2
  2. package/README.md +85 -37
  3. package/THIRD_PARTY_NOTICES.md +197 -29
  4. package/dist/core/compute/atlas.d.ts +10 -2
  5. package/dist/core/compute/atlas.js +6 -1
  6. package/dist/core/compute/atlas.js.map +1 -1
  7. package/dist/core/compute/index.d.ts +3 -3
  8. package/dist/core/compute/index.js +2 -2
  9. package/dist/core/compute/index.js.map +1 -1
  10. package/dist/core/compute/majorant-build.d.ts +45 -0
  11. package/dist/core/compute/majorant-build.js +193 -0
  12. package/dist/core/compute/majorant-build.js.map +1 -0
  13. package/dist/core/compute/multi-scale.d.ts +155 -0
  14. package/dist/core/compute/multi-scale.js +684 -0
  15. package/dist/core/compute/multi-scale.js.map +1 -0
  16. package/dist/core/compute/pyramid.d.ts +22 -7
  17. package/dist/core/compute/pyramid.js +22 -9
  18. package/dist/core/compute/pyramid.js.map +1 -1
  19. package/dist/core/compute/shared.d.ts +1 -0
  20. package/dist/core/compute/shared.js.map +1 -1
  21. package/dist/core/compute/stats.d.ts +10 -3
  22. package/dist/core/compute/stats.js +6 -1
  23. package/dist/core/compute/stats.js.map +1 -1
  24. package/dist/core/compute/value-transform.d.ts +8 -1
  25. package/dist/core/compute/value-transform.js +9 -3
  26. package/dist/core/compute/value-transform.js.map +1 -1
  27. package/dist/core/errors.d.ts +10 -0
  28. package/dist/core/errors.js +8 -0
  29. package/dist/core/errors.js.map +1 -1
  30. package/dist/core/frame/emission.d.ts +85 -0
  31. package/dist/core/frame/emission.js +422 -0
  32. package/dist/core/frame/emission.js.map +1 -0
  33. package/dist/core/frame/environment.d.ts +47 -0
  34. package/dist/core/frame/environment.js +178 -0
  35. package/dist/core/frame/environment.js.map +1 -0
  36. package/dist/core/frame/index.d.ts +39 -0
  37. package/dist/core/frame/index.js +27 -0
  38. package/dist/core/frame/index.js.map +1 -0
  39. package/dist/core/frame/kernels.d.ts +115 -0
  40. package/dist/core/frame/kernels.js +496 -0
  41. package/dist/core/frame/kernels.js.map +1 -0
  42. package/dist/core/frame/limits.d.ts +67 -0
  43. package/dist/core/frame/limits.js +109 -0
  44. package/dist/core/frame/limits.js.map +1 -0
  45. package/dist/core/frame/phase.d.ts +17 -0
  46. package/dist/core/frame/phase.js +53 -0
  47. package/dist/core/frame/phase.js.map +1 -0
  48. package/dist/core/frame/pipelines.d.ts +49 -0
  49. package/dist/core/frame/pipelines.js +147 -0
  50. package/dist/core/frame/pipelines.js.map +1 -0
  51. package/dist/core/frame/renderer.d.ts +122 -0
  52. package/dist/core/frame/renderer.js +1712 -0
  53. package/dist/core/frame/renderer.js.map +1 -0
  54. package/dist/core/frame/resources.d.ts +71 -0
  55. package/dist/core/frame/resources.js +100 -0
  56. package/dist/core/frame/resources.js.map +1 -0
  57. package/dist/core/frame/scattering.d.ts +97 -0
  58. package/dist/core/frame/scattering.js +332 -0
  59. package/dist/core/frame/scattering.js.map +1 -0
  60. package/dist/core/frame/settings.d.ts +243 -0
  61. package/dist/core/frame/settings.js +67 -0
  62. package/dist/core/frame/settings.js.map +1 -0
  63. package/dist/core/frame/shadows.d.ts +55 -0
  64. package/dist/core/frame/shadows.js +460 -0
  65. package/dist/core/frame/shadows.js.map +1 -0
  66. package/dist/core/frame/types.d.ts +415 -0
  67. package/dist/core/frame/types.js +49 -0
  68. package/dist/core/frame/types.js.map +1 -0
  69. package/dist/core/frame/uniforms.d.ts +105 -0
  70. package/dist/core/frame/uniforms.js +276 -0
  71. package/dist/core/frame/uniforms.js.map +1 -0
  72. package/dist/core/frame/wgsl/chunks.d.ts +4 -0
  73. package/dist/core/frame/wgsl/chunks.js +728 -0
  74. package/dist/core/frame/wgsl/chunks.js.map +1 -0
  75. package/dist/core/frame/wgsl/emission.d.ts +82 -0
  76. package/dist/core/frame/wgsl/emission.js +353 -0
  77. package/dist/core/frame/wgsl/emission.js.map +1 -0
  78. package/dist/core/frame/wgsl/environment.d.ts +42 -0
  79. package/dist/core/frame/wgsl/environment.js +711 -0
  80. package/dist/core/frame/wgsl/environment.js.map +1 -0
  81. package/dist/core/frame/wgsl/gather.d.ts +55 -0
  82. package/dist/core/frame/wgsl/gather.js +850 -0
  83. package/dist/core/frame/wgsl/gather.js.map +1 -0
  84. package/dist/core/frame/wgsl/integrate.d.ts +78 -0
  85. package/dist/core/frame/wgsl/integrate.js +213 -0
  86. package/dist/core/frame/wgsl/integrate.js.map +1 -0
  87. package/dist/core/frame/wgsl/lighting.d.ts +103 -0
  88. package/dist/core/frame/wgsl/lighting.js +1636 -0
  89. package/dist/core/frame/wgsl/lighting.js.map +1 -0
  90. package/dist/core/frame/wgsl/occluders.d.ts +20 -0
  91. package/dist/core/frame/wgsl/occluders.js +95 -0
  92. package/dist/core/frame/wgsl/occluders.js.map +1 -0
  93. package/dist/core/frame/wgsl/resolve.d.ts +19 -0
  94. package/dist/core/frame/wgsl/resolve.js +205 -0
  95. package/dist/core/frame/wgsl/resolve.js.map +1 -0
  96. package/dist/core/frame/wgsl/shadows.d.ts +35 -0
  97. package/dist/core/frame/wgsl/shadows.js +328 -0
  98. package/dist/core/frame/wgsl/shadows.js.map +1 -0
  99. package/dist/core/half.d.ts +11 -0
  100. package/dist/core/half.js +22 -0
  101. package/dist/core/half.js.map +1 -0
  102. package/dist/core/index.d.ts +25 -3
  103. package/dist/core/index.js +23 -4
  104. package/dist/core/index.js.map +1 -1
  105. package/dist/core/internal.d.ts +17 -1
  106. package/dist/core/internal.js +18 -1
  107. package/dist/core/internal.js.map +1 -1
  108. package/dist/core/pool/image-header.d.ts +13 -2
  109. package/dist/core/pool/image-header.js +24 -5
  110. package/dist/core/pool/image-header.js.map +1 -1
  111. package/dist/core/pool/layout.d.ts +35 -1
  112. package/dist/core/pool/layout.js +51 -2
  113. package/dist/core/pool/layout.js.map +1 -1
  114. package/dist/core/pool/limits.d.ts +1 -0
  115. package/dist/core/pool/limits.js +1 -0
  116. package/dist/core/pool/limits.js.map +1 -1
  117. package/dist/core/pool/pool.d.ts +120 -15
  118. package/dist/core/pool/pool.js +255 -24
  119. package/dist/core/pool/pool.js.map +1 -1
  120. package/dist/core/reference/index.d.ts +6 -0
  121. package/dist/core/reference/index.js +7 -0
  122. package/dist/core/reference/index.js.map +1 -0
  123. package/dist/core/reference/renderer.d.ts +105 -0
  124. package/dist/core/reference/renderer.js +474 -0
  125. package/dist/core/reference/renderer.js.map +1 -0
  126. package/dist/core/reference/wgsl.d.ts +65 -0
  127. package/dist/core/reference/wgsl.js +803 -0
  128. package/dist/core/reference/wgsl.js.map +1 -0
  129. package/dist/{three → core}/sequence.d.ts +32 -2
  130. package/dist/{three → core}/sequence.js +24 -2
  131. package/dist/core/sequence.js.map +1 -0
  132. package/dist/core/source/brick-cache.d.ts +165 -0
  133. package/dist/core/source/brick-cache.js +627 -0
  134. package/dist/core/source/brick-cache.js.map +1 -0
  135. package/dist/core/source/dense-fill.d.ts +53 -0
  136. package/dist/core/source/dense-fill.js +377 -0
  137. package/dist/core/source/dense-fill.js.map +1 -0
  138. package/dist/core/source/dense.d.ts +33 -2
  139. package/dist/core/source/dense.js +121 -24
  140. package/dist/core/source/dense.js.map +1 -1
  141. package/dist/core/source/sparse-wgsl.d.ts +92 -0
  142. package/dist/core/source/sparse-wgsl.js +481 -0
  143. package/dist/core/source/sparse-wgsl.js.map +1 -0
  144. package/dist/core/source/sparse.d.ts +192 -0
  145. package/dist/core/source/sparse.js +762 -0
  146. package/dist/core/source/sparse.js.map +1 -0
  147. package/dist/core/source/types.d.ts +59 -2
  148. package/dist/core/source/types.js.map +1 -1
  149. package/dist/core/surface/index.d.ts +10 -0
  150. package/dist/core/surface/index.js +9 -0
  151. package/dist/core/surface/index.js.map +1 -0
  152. package/dist/core/surface/level-set-pass.d.ts +140 -0
  153. package/dist/core/surface/level-set-pass.js +291 -0
  154. package/dist/core/surface/level-set-pass.js.map +1 -0
  155. package/dist/core/surface/level-set-wgsl.d.ts +46 -0
  156. package/dist/core/surface/level-set-wgsl.js +99 -0
  157. package/dist/core/surface/level-set-wgsl.js.map +1 -0
  158. package/dist/core/surface/points.d.ts +109 -0
  159. package/dist/core/surface/points.js +226 -0
  160. package/dist/core/surface/points.js.map +1 -0
  161. package/dist/core/types.d.ts +12 -3
  162. package/dist/core/types.js +6 -2
  163. package/dist/core/types.js.map +1 -1
  164. package/dist/core/wgsl/api.d.ts +29 -5
  165. package/dist/core/wgsl/api.js +110 -27
  166. package/dist/core/wgsl/api.js.map +1 -1
  167. package/dist/core/wgsl/generate.d.ts +8 -0
  168. package/dist/core/wgsl/generate.js +195 -22
  169. package/dist/core/wgsl/generate.js.map +1 -1
  170. package/dist/core/wgsl/lean.d.ts +50 -0
  171. package/dist/core/wgsl/lean.js +327 -0
  172. package/dist/core/wgsl/lean.js.map +1 -0
  173. package/dist/core/wgsl/level-set.d.ts +5 -1
  174. package/dist/core/wgsl/level-set.js +11 -5
  175. package/dist/core/wgsl/level-set.js.map +1 -1
  176. package/dist/core/wgsl/majorant.d.ts +62 -0
  177. package/dist/core/wgsl/majorant.js +381 -0
  178. package/dist/core/wgsl/majorant.js.map +1 -0
  179. package/dist/core/wgsl/pnanovdb.chunks.generated.d.ts +2 -2
  180. package/dist/core/wgsl/pnanovdb.chunks.generated.js +15 -12
  181. package/dist/core/wgsl/pnanovdb.chunks.generated.js.map +1 -1
  182. package/dist/core/wgsl/types.d.ts +97 -3
  183. package/dist/core/wgsl/types.js.map +1 -1
  184. package/dist/three/coarse-first.d.ts +53 -8
  185. package/dist/three/coarse-first.js +24 -6
  186. package/dist/three/coarse-first.js.map +1 -1
  187. package/dist/three/compute.d.ts +12 -2
  188. package/dist/three/compute.js +16 -6
  189. package/dist/three/compute.js.map +1 -1
  190. package/dist/three/device.d.ts +7 -0
  191. package/dist/three/device.js +3 -0
  192. package/dist/three/device.js.map +1 -1
  193. package/dist/three/frame/core-environment.d.ts +38 -0
  194. package/dist/three/frame/core-environment.js +154 -0
  195. package/dist/three/frame/core-environment.js.map +1 -0
  196. package/dist/three/frame/core-integrate-material.d.ts +34 -0
  197. package/dist/three/frame/core-integrate-material.js +162 -0
  198. package/dist/three/frame/core-integrate-material.js.map +1 -0
  199. package/dist/three/frame/core-occluders.d.ts +53 -0
  200. package/dist/three/frame/core-occluders.js +193 -0
  201. package/dist/three/frame/core-occluders.js.map +1 -0
  202. package/dist/three/frame/core-structs.d.ts +34 -0
  203. package/dist/three/frame/core-structs.js +61 -0
  204. package/dist/three/frame/core-structs.js.map +1 -0
  205. package/dist/three/frame/core-textures.d.ts +41 -0
  206. package/dist/three/frame/core-textures.js +114 -0
  207. package/dist/three/frame/core-textures.js.map +1 -0
  208. package/dist/three/frame/emission-light.d.ts +64 -114
  209. package/dist/three/frame/emission-light.js +188 -567
  210. package/dist/three/frame/emission-light.js.map +1 -1
  211. package/dist/three/frame/index.d.ts +11 -31
  212. package/dist/three/frame/index.js +9 -29
  213. package/dist/three/frame/index.js.map +1 -1
  214. package/dist/three/frame/medium.d.ts +12 -0
  215. package/dist/three/frame/medium.js.map +1 -1
  216. package/dist/three/frame/renderer.d.ts +58 -454
  217. package/dist/three/frame/renderer.js +409 -1427
  218. package/dist/three/frame/renderer.js.map +1 -1
  219. package/dist/three/frame/spectrum.d.ts +0 -14
  220. package/dist/three/frame/spectrum.js +2 -23
  221. package/dist/three/frame/spectrum.js.map +1 -1
  222. package/dist/three/frame/three-internals.d.ts +3 -8
  223. package/dist/three/frame/three-internals.js +13 -11
  224. package/dist/three/frame/three-internals.js.map +1 -1
  225. package/dist/three/frame/volume-shadows.d.ts +93 -107
  226. package/dist/three/frame/volume-shadows.js +278 -631
  227. package/dist/three/frame/volume-shadows.js.map +1 -1
  228. package/dist/three/frame/volume.d.ts +91 -33
  229. package/dist/three/frame/volume.js +63 -51
  230. package/dist/three/frame/volume.js.map +1 -1
  231. package/dist/three/grid-node.d.ts +34 -1
  232. package/dist/three/grid-node.js +36 -1
  233. package/dist/three/grid-node.js.map +1 -1
  234. package/dist/three/index.d.ts +20 -11
  235. package/dist/three/index.js +21 -12
  236. package/dist/three/index.js.map +1 -1
  237. package/dist/three/internal.d.ts +14 -8
  238. package/dist/three/internal.js +11 -7
  239. package/dist/three/internal.js.map +1 -1
  240. package/dist/three/level-set-material.d.ts +81 -8
  241. package/dist/three/level-set-material.js +162 -125
  242. package/dist/three/level-set-material.js.map +1 -1
  243. package/dist/three/level-set-physical-material.d.ts +154 -0
  244. package/dist/three/level-set-physical-material.js +253 -0
  245. package/dist/three/level-set-physical-material.js.map +1 -0
  246. package/dist/three/level-set-velocity.d.ts +94 -0
  247. package/dist/three/level-set-velocity.js +208 -0
  248. package/dist/three/level-set-velocity.js.map +1 -0
  249. package/dist/three/material.d.ts +141 -11
  250. package/dist/three/material.js +161 -18
  251. package/dist/three/material.js.map +1 -1
  252. package/dist/three/points.d.ts +60 -4
  253. package/dist/three/points.js +140 -9
  254. package/dist/three/points.js.map +1 -1
  255. package/dist/three/sparse-source.d.ts +49 -117
  256. package/dist/three/sparse-source.js +109 -580
  257. package/dist/three/sparse-source.js.map +1 -1
  258. package/dist/three/volume-source.d.ts +11 -156
  259. package/dist/three/volume-source.js +29 -272
  260. package/dist/three/volume-source.js.map +1 -1
  261. package/dist/tools/cpu/brick-atlas.d.ts +36 -0
  262. package/dist/tools/cpu/brick-atlas.js +129 -0
  263. package/dist/tools/cpu/brick-atlas.js.map +1 -0
  264. package/dist/tools/cpu/compute.d.ts +23 -4
  265. package/dist/tools/cpu/compute.js +35 -14
  266. package/dist/tools/cpu/compute.js.map +1 -1
  267. package/dist/tools/cpu/lean-reads.d.ts +81 -0
  268. package/dist/tools/cpu/lean-reads.js +262 -0
  269. package/dist/tools/cpu/lean-reads.js.map +1 -0
  270. package/dist/tools/cpu/level-set.d.ts +42 -3
  271. package/dist/tools/cpu/level-set.js +59 -7
  272. package/dist/tools/cpu/level-set.js.map +1 -1
  273. package/dist/tools/cpu/majorant.d.ts +265 -0
  274. package/dist/tools/cpu/majorant.js +541 -0
  275. package/dist/tools/cpu/majorant.js.map +1 -0
  276. package/dist/tools/cpu/march.d.ts +93 -2
  277. package/dist/tools/cpu/march.js +165 -14
  278. package/dist/tools/cpu/march.js.map +1 -1
  279. package/dist/tools/cpu/mesh-decimate.d.ts +124 -0
  280. package/dist/tools/cpu/mesh-decimate.js +1225 -0
  281. package/dist/tools/cpu/mesh-decimate.js.map +1 -0
  282. package/dist/tools/cpu/points.d.ts +29 -0
  283. package/dist/tools/cpu/points.js +38 -0
  284. package/dist/tools/cpu/points.js.map +1 -0
  285. package/dist/tools/cpu/read-value.d.ts +19 -6
  286. package/dist/tools/cpu/read-value.js +32 -17
  287. package/dist/tools/cpu/read-value.js.map +1 -1
  288. package/dist/tools/cpu/sample-trilinear.d.ts +17 -4
  289. package/dist/tools/cpu/sample-trilinear.js +19 -7
  290. package/dist/tools/cpu/sample-trilinear.js.map +1 -1
  291. package/dist/tools/cpu/stride-tables.d.ts +2 -2
  292. package/dist/tools/cpu/stride-tables.generated.d.ts +6 -5
  293. package/dist/tools/cpu/stride-tables.generated.js +7 -6
  294. package/dist/tools/cpu/stride-tables.generated.js.map +1 -1
  295. package/dist/tools/cpu/stride-tables.js +1 -1
  296. package/dist/tools/cpu/stride-tables.js.map +1 -1
  297. package/dist/tools/cpu/surface-nets.d.ts +90 -0
  298. package/dist/tools/cpu/surface-nets.js +597 -0
  299. package/dist/tools/cpu/surface-nets.js.map +1 -0
  300. package/dist/tools/errors.d.ts +9 -0
  301. package/dist/tools/errors.js +9 -0
  302. package/dist/tools/errors.js.map +1 -1
  303. package/dist/tools/frame/ambient.d.ts +98 -0
  304. package/dist/tools/frame/ambient.js +274 -0
  305. package/dist/tools/frame/ambient.js.map +1 -0
  306. package/dist/tools/frame/blackbody.d.ts +15 -0
  307. package/dist/tools/frame/blackbody.js +35 -0
  308. package/dist/tools/frame/blackbody.js.map +1 -1
  309. package/dist/tools/frame/brick-cache.d.ts +165 -0
  310. package/dist/tools/frame/brick-cache.js +326 -0
  311. package/dist/tools/frame/brick-cache.js.map +1 -0
  312. package/dist/tools/frame/emission.d.ts +9 -0
  313. package/dist/tools/frame/emission.js +9 -1
  314. package/dist/tools/frame/emission.js.map +1 -1
  315. package/dist/tools/frame/environment-gpu.d.ts +111 -0
  316. package/dist/tools/frame/environment-gpu.js +280 -0
  317. package/dist/tools/frame/environment-gpu.js.map +1 -0
  318. package/dist/tools/frame/environment.d.ts +3 -2
  319. package/dist/tools/frame/environment.js +8 -4
  320. package/dist/tools/frame/environment.js.map +1 -1
  321. package/dist/tools/frame/froxel.d.ts +58 -0
  322. package/dist/tools/frame/froxel.js +115 -0
  323. package/dist/tools/frame/froxel.js.map +1 -0
  324. package/dist/tools/frame/grid.d.ts +90 -0
  325. package/dist/tools/frame/grid.js +112 -13
  326. package/dist/tools/frame/grid.js.map +1 -1
  327. package/dist/tools/frame/index.d.ts +14 -0
  328. package/dist/tools/frame/index.js +45 -4
  329. package/dist/tools/frame/index.js.map +1 -1
  330. package/dist/tools/frame/medium.d.ts +16 -0
  331. package/dist/tools/frame/medium.js +3 -1
  332. package/dist/tools/frame/medium.js.map +1 -1
  333. package/dist/tools/frame/mie.d.ts +9 -0
  334. package/dist/tools/frame/mie.js +18 -0
  335. package/dist/tools/frame/mie.js.map +1 -1
  336. package/dist/tools/frame/mlp-nn.d.ts +36 -0
  337. package/dist/tools/frame/mlp-nn.js +159 -0
  338. package/dist/tools/frame/mlp-nn.js.map +1 -0
  339. package/dist/tools/frame/mlp-tza.d.ts +29 -0
  340. package/dist/tools/frame/mlp-tza.js +186 -0
  341. package/dist/tools/frame/mlp-tza.js.map +1 -0
  342. package/dist/tools/frame/mlp.d.ts +183 -0
  343. package/dist/tools/frame/mlp.js +434 -0
  344. package/dist/tools/frame/mlp.js.map +1 -0
  345. package/dist/tools/frame/ms-exit.d.ts +42 -0
  346. package/dist/tools/frame/ms-exit.js +90 -0
  347. package/dist/tools/frame/ms-exit.js.map +1 -0
  348. package/dist/tools/frame/multi-scale.d.ts +152 -0
  349. package/dist/tools/frame/multi-scale.js +302 -0
  350. package/dist/tools/frame/multi-scale.js.map +1 -0
  351. package/dist/tools/frame/neural-weights.d.ts +6 -5
  352. package/dist/tools/frame/neural-weights.js +234 -235
  353. package/dist/tools/frame/neural-weights.js.map +1 -1
  354. package/dist/tools/frame/neural.js +1 -1
  355. package/dist/tools/frame/neural.js.map +1 -1
  356. package/dist/tools/frame/occluders.d.ts +51 -0
  357. package/dist/tools/frame/occluders.js +72 -0
  358. package/dist/tools/frame/occluders.js.map +1 -0
  359. package/dist/tools/frame/pyramid-layout.d.ts +17 -0
  360. package/dist/tools/frame/pyramid-layout.js +47 -0
  361. package/dist/tools/frame/pyramid-layout.js.map +1 -1
  362. package/dist/tools/frame/shadows.d.ts +110 -0
  363. package/dist/tools/frame/shadows.js +286 -0
  364. package/dist/tools/frame/shadows.js.map +1 -1
  365. package/dist/tools/frame/sparse.d.ts +82 -0
  366. package/dist/tools/frame/sparse.js +242 -1
  367. package/dist/tools/frame/sparse.js.map +1 -1
  368. package/dist/tools/frame/spectral-stack.d.ts +159 -0
  369. package/dist/tools/frame/spectral-stack.js +391 -0
  370. package/dist/tools/frame/spectral-stack.js.map +1 -0
  371. package/dist/tools/frame/spectral.d.ts +21 -2
  372. package/dist/tools/frame/spectral.js +30 -8
  373. package/dist/tools/frame/spectral.js.map +1 -1
  374. package/dist/tools/frame/stack.d.ts +115 -0
  375. package/dist/tools/frame/stack.js +290 -0
  376. package/dist/tools/frame/stack.js.map +1 -0
  377. package/dist/tools/frame/view.d.ts +131 -0
  378. package/dist/tools/frame/view.js +337 -0
  379. package/dist/tools/frame/view.js.map +1 -0
  380. package/dist/tools/index.d.ts +66 -15
  381. package/dist/tools/index.js +55 -11
  382. package/dist/tools/index.js.map +1 -1
  383. package/dist/tools/internal.d.ts +58 -17
  384. package/dist/tools/internal.js +65 -11
  385. package/dist/tools/internal.js.map +1 -1
  386. package/dist/tools/nanovdb/build-from-vdb.d.ts +11 -2
  387. package/dist/tools/nanovdb/build-from-vdb.js +10 -2
  388. package/dist/tools/nanovdb/build-from-vdb.js.map +1 -1
  389. package/dist/tools/nanovdb/bytes.d.ts +17 -4
  390. package/dist/tools/nanovdb/bytes.js +46 -3
  391. package/dist/tools/nanovdb/bytes.js.map +1 -1
  392. package/dist/tools/nanovdb/coarse-first.d.ts +19 -3
  393. package/dist/tools/nanovdb/coarse-first.js +7 -1
  394. package/dist/tools/nanovdb/coarse-first.js.map +1 -1
  395. package/dist/tools/nanovdb/half.d.ts +22 -0
  396. package/dist/tools/nanovdb/half.js +73 -0
  397. package/dist/tools/nanovdb/half.js.map +1 -0
  398. package/dist/tools/nanovdb/index.d.ts +3 -1
  399. package/dist/tools/nanovdb/index.js +2 -1
  400. package/dist/tools/nanovdb/index.js.map +1 -1
  401. package/dist/tools/nanovdb/inspect.d.ts +10 -1
  402. package/dist/tools/nanovdb/inspect.js +8 -1
  403. package/dist/tools/nanovdb/inspect.js.map +1 -1
  404. package/dist/tools/nanovdb/leaf-codec.d.ts +35 -1
  405. package/dist/tools/nanovdb/leaf-codec.js +40 -4
  406. package/dist/tools/nanovdb/leaf-codec.js.map +1 -1
  407. package/dist/tools/nanovdb/quantize.d.ts +39 -10
  408. package/dist/tools/nanovdb/quantize.js +96 -44
  409. package/dist/tools/nanovdb/quantize.js.map +1 -1
  410. package/dist/tools/nanovdb/resample.d.ts +20 -3
  411. package/dist/tools/nanovdb/resample.js +20 -7
  412. package/dist/tools/nanovdb/resample.js.map +1 -1
  413. package/dist/tools/nanovdb/serialize.d.ts +34 -3
  414. package/dist/tools/nanovdb/serialize.js +51 -7
  415. package/dist/tools/nanovdb/serialize.js.map +1 -1
  416. package/dist/tools/nanovdb/stats.d.ts +34 -5
  417. package/dist/tools/nanovdb/stats.js +87 -11
  418. package/dist/tools/nanovdb/stats.js.map +1 -1
  419. package/dist/tools/nanovdb/transform.d.ts +4 -0
  420. package/dist/tools/nanovdb/transform.js +3 -0
  421. package/dist/tools/nanovdb/transform.js.map +1 -1
  422. package/dist/tools/nanovdb/tree.d.ts +14 -3
  423. package/dist/tools/nanovdb/tree.js +25 -13
  424. package/dist/tools/nanovdb/tree.js.map +1 -1
  425. package/dist/tools/nanovdb/write-nvdb.d.ts +47 -12
  426. package/dist/tools/nanovdb/write-nvdb.js +108 -28
  427. package/dist/tools/nanovdb/write-nvdb.js.map +1 -1
  428. package/dist/tools/nvdb-file.d.ts +77 -7
  429. package/dist/tools/nvdb-file.js +177 -20
  430. package/dist/tools/nvdb-file.js.map +1 -1
  431. package/dist/tools/nvdb-stream.d.ts +23 -7
  432. package/dist/tools/nvdb-stream.js +78 -34
  433. package/dist/tools/nvdb-stream.js.map +1 -1
  434. package/dist/tools/reference/analytic.d.ts +41 -0
  435. package/dist/tools/reference/analytic.js +95 -0
  436. package/dist/tools/reference/analytic.js.map +1 -0
  437. package/dist/tools/reference/environment.d.ts +62 -0
  438. package/dist/tools/reference/environment.js +154 -0
  439. package/dist/tools/reference/environment.js.map +1 -0
  440. package/dist/tools/reference/index.d.ts +12 -0
  441. package/dist/tools/reference/index.js +13 -0
  442. package/dist/tools/reference/index.js.map +1 -0
  443. package/dist/tools/reference/media.d.ts +14 -0
  444. package/dist/tools/reference/media.js +30 -0
  445. package/dist/tools/reference/media.js.map +1 -0
  446. package/dist/tools/reference/rng.d.ts +20 -0
  447. package/dist/tools/reference/rng.js +30 -0
  448. package/dist/tools/reference/rng.js.map +1 -0
  449. package/dist/tools/reference/scene.d.ts +312 -0
  450. package/dist/tools/reference/scene.js +169 -0
  451. package/dist/tools/reference/scene.js.map +1 -0
  452. package/dist/tools/reference/tables.d.ts +98 -0
  453. package/dist/tools/reference/tables.js +264 -0
  454. package/dist/tools/reference/tables.js.map +1 -0
  455. package/dist/tools/reference/trace.d.ts +160 -0
  456. package/dist/tools/reference/trace.js +497 -0
  457. package/dist/tools/reference/trace.js.map +1 -0
  458. package/dist/tools/vdb/blosc-write.d.ts +43 -0
  459. package/dist/tools/vdb/blosc-write.js +197 -0
  460. package/dist/tools/vdb/blosc-write.js.map +1 -0
  461. package/dist/tools/vdb/blosc.d.ts +35 -5
  462. package/dist/tools/vdb/blosc.js +82 -26
  463. package/dist/tools/vdb/blosc.js.map +1 -1
  464. package/dist/tools/vdb/blosclz.d.ts +33 -0
  465. package/dist/tools/vdb/blosclz.js +112 -0
  466. package/dist/tools/vdb/blosclz.js.map +1 -0
  467. package/dist/tools/vdb/byte-reader.d.ts +13 -3
  468. package/dist/tools/vdb/byte-reader.js +26 -4
  469. package/dist/tools/vdb/byte-reader.js.map +1 -1
  470. package/dist/tools/vdb/compression.d.ts +13 -5
  471. package/dist/tools/vdb/compression.js +13 -2
  472. package/dist/tools/vdb/compression.js.map +1 -1
  473. package/dist/tools/vdb/grid.js +8 -2
  474. package/dist/tools/vdb/grid.js.map +1 -1
  475. package/dist/tools/vdb/index.d.ts +2 -1
  476. package/dist/tools/vdb/index.js.map +1 -1
  477. package/dist/tools/vdb/lz4.d.ts +30 -0
  478. package/dist/tools/vdb/lz4.js +228 -0
  479. package/dist/tools/vdb/lz4.js.map +1 -0
  480. package/dist/tools/vdb/metadata.js +1 -1
  481. package/dist/tools/vdb/metadata.js.map +1 -1
  482. package/dist/tools/vdb/parse.d.ts +24 -2
  483. package/dist/tools/vdb/parse.js +102 -32
  484. package/dist/tools/vdb/parse.js.map +1 -1
  485. package/dist/tools/vdb/point-render-data.d.ts +49 -1
  486. package/dist/tools/vdb/point-render-data.js +91 -11
  487. package/dist/tools/vdb/point-render-data.js.map +1 -1
  488. package/dist/tools/vdb/points.d.ts +26 -0
  489. package/dist/tools/vdb/points.js +46 -5
  490. package/dist/tools/vdb/points.js.map +1 -1
  491. package/dist/tools/vdb/types.d.ts +59 -2
  492. package/dist/tools/vdb/types.js.map +1 -1
  493. package/dist/tools/wvdb/bake.d.ts +38 -9
  494. package/dist/tools/wvdb/bake.js +63 -13
  495. package/dist/tools/wvdb/bake.js.map +1 -1
  496. package/dist/tools/wvdb/dense.d.ts +80 -1
  497. package/dist/tools/wvdb/dense.js +67 -8
  498. package/dist/tools/wvdb/dense.js.map +1 -1
  499. package/dist/tools/wvdb/format.d.ts +59 -0
  500. package/dist/tools/wvdb/format.js +3 -0
  501. package/dist/tools/wvdb/format.js.map +1 -1
  502. package/dist/tools/wvdb/index.d.ts +1 -0
  503. package/dist/tools/wvdb/index.js +1 -0
  504. package/dist/tools/wvdb/index.js.map +1 -1
  505. package/dist/tools/wvdb/level-set.d.ts +10 -2
  506. package/dist/tools/wvdb/level-set.js.map +1 -1
  507. package/dist/tools/wvdb/nanovdb.d.ts +6 -1
  508. package/dist/tools/wvdb/nanovdb.js +5 -1
  509. package/dist/tools/wvdb/nanovdb.js.map +1 -1
  510. package/dist/tools/wvdb/partial.d.ts +74 -0
  511. package/dist/tools/wvdb/partial.js +233 -0
  512. package/dist/tools/wvdb/partial.js.map +1 -0
  513. package/dist/tools/wvdb/read.d.ts +77 -1
  514. package/dist/tools/wvdb/read.js +30 -7
  515. package/dist/tools/wvdb/read.js.map +1 -1
  516. package/dist/tools/wvdb/write.d.ts +23 -1
  517. package/dist/tools/wvdb/write.js +8 -1
  518. package/dist/tools/wvdb/write.js.map +1 -1
  519. package/package.json +2 -1
  520. package/vendor/VENDOR.md +21 -6
  521. package/vendor/pnanovdb.wgsl +52 -14
  522. package/dist/three/frame/blackbody.d.ts +0 -42
  523. package/dist/three/frame/blackbody.js +0 -74
  524. package/dist/three/frame/blackbody.js.map +0 -1
  525. package/dist/three/frame/chunks.d.ts +0 -157
  526. package/dist/three/frame/chunks.js +0 -559
  527. package/dist/three/frame/chunks.js.map +0 -1
  528. package/dist/three/frame/density-material.d.ts +0 -53
  529. package/dist/three/frame/density-material.js +0 -353
  530. package/dist/three/frame/density-material.js.map +0 -1
  531. package/dist/three/frame/environment-grid-material.d.ts +0 -21
  532. package/dist/three/frame/environment-grid-material.js +0 -184
  533. package/dist/three/frame/environment-grid-material.js.map +0 -1
  534. package/dist/three/frame/environment-material.d.ts +0 -22
  535. package/dist/three/frame/environment-material.js +0 -87
  536. package/dist/three/frame/environment-material.js.map +0 -1
  537. package/dist/three/frame/grid-mip-material.d.ts +0 -12
  538. package/dist/three/frame/grid-mip-material.js +0 -61
  539. package/dist/three/frame/grid-mip-material.js.map +0 -1
  540. package/dist/three/frame/inject-material.d.ts +0 -56
  541. package/dist/three/frame/inject-material.js +0 -424
  542. package/dist/three/frame/inject-material.js.map +0 -1
  543. package/dist/three/frame/integrate-material.d.ts +0 -26
  544. package/dist/three/frame/integrate-material.js +0 -198
  545. package/dist/three/frame/integrate-material.js.map +0 -1
  546. package/dist/three/frame/layout.d.ts +0 -34
  547. package/dist/three/frame/layout.js +0 -48
  548. package/dist/three/frame/layout.js.map +0 -1
  549. package/dist/three/frame/lighting-material.d.ts +0 -41
  550. package/dist/three/frame/lighting-material.js +0 -257
  551. package/dist/three/frame/lighting-material.js.map +0 -1
  552. package/dist/three/frame/lights.d.ts +0 -11
  553. package/dist/three/frame/lights.js +0 -16
  554. package/dist/three/frame/lights.js.map +0 -1
  555. package/dist/three/frame/neural.d.ts +0 -14
  556. package/dist/three/frame/neural.js +0 -105
  557. package/dist/three/frame/neural.js.map +0 -1
  558. package/dist/three/frame/phase.d.ts +0 -44
  559. package/dist/three/frame/phase.js +0 -80
  560. package/dist/three/frame/phase.js.map +0 -1
  561. package/dist/three/frame/shadow-density-material.d.ts +0 -30
  562. package/dist/three/frame/shadow-density-material.js +0 -123
  563. package/dist/three/frame/shadow-density-material.js.map +0 -1
  564. package/dist/three/frame/temporal-material.d.ts +0 -29
  565. package/dist/three/frame/temporal-material.js +0 -152
  566. package/dist/three/frame/temporal-material.js.map +0 -1
  567. package/dist/three/frame/transmittance-material.d.ts +0 -31
  568. package/dist/three/frame/transmittance-material.js +0 -315
  569. package/dist/three/frame/transmittance-material.js.map +0 -1
  570. package/dist/three/frame/view.d.ts +0 -103
  571. package/dist/three/frame/view.js +0 -296
  572. package/dist/three/frame/view.js.map +0 -1
  573. package/dist/three/frame/volume-shadow-material.d.ts +0 -36
  574. package/dist/three/frame/volume-shadow-material.js +0 -128
  575. package/dist/three/frame/volume-shadow-material.js.map +0 -1
  576. package/dist/three/sequence.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tools/nanovdb/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EACL,iBAAiB,EACjB,yBAAyB,EACzB,0BAA0B,GAC3B,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAEzE,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAElF,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAUpF,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC","sourcesContent":["/**\n * nanovdb/ — pure-TypeScript NanoVDB serializer (Phase 5, decision D3).\n *\n * Public surface for the orchestrator to re-export from the package root:\n * - `vdbBuildFromDense(values, dims, opts?)` -> a complete, valid FLOAT NanoVDB\n * grid image (flat u32 array) that the repo's proven readers accept.\n * - `writeNvdb(images, opts?)` -> a segment-format `.nvdb` file ArrayBuffer.\n * - `vdbBuildFromDenseDetailed(...)` -> image + computed metadata.\n *\n * Module map: bytes.ts (offsets + writer), tree.ts (dense -> sparse topology),\n * stats.ts (GridStats-style node stats), leaf-codec.ts (leaf value encoding —\n * the abstraction Fp8/FpN slot into next wave), serialize.ts (layout), and\n * write-nvdb.ts (file framing).\n */\n\nexport {\n vdbBuildFromDense,\n vdbBuildFromDenseDetailed,\n vdbBuildFromLeavesDetailed,\n} from \"./serialize.js\";\nexport type { VDBBuildFromDenseOptions, VDBBuildFromLeavesOptions, VDBBuiltGrid } from \"./serialize.js\";\nexport { writeNvdb } from \"./write-nvdb.js\";\nexport type { WriteNvdbOptions } from \"./write-nvdb.js\";\nexport type { VDBLeafCodec } from \"./leaf-codec.js\";\nexport {\n VDB_FLOAT_LEAF_CODEC,\n VDB_FP4_LEAF_CODEC,\n VDB_FP8_LEAF_CODEC,\n VDB_FP16_LEAF_CODEC,\n vdbMakeFpNLeafCodec,\n FPN_DEFAULT_TOLERANCE,\n VDB_VEC3F_LEAF_CODEC,\n} from \"./leaf-codec.js\";\nexport { buildFromVdb, buildFromVdbDetailed } from \"./build-from-vdb.js\";\nexport type { BuildFromVdbOptions } from \"./build-from-vdb.js\";\nexport { vdbCollapseGrid, vdbQuantize, vdbQuantizeDetailed } from \"./quantize.js\";\nexport type { VDBQuantizeMode, VDBQuantizeOptions } from \"./quantize.js\";\nexport { vdbResampleGrid, vdbResampleError, vdbResampleDense } from \"./resample.js\";\nexport type {\n VDBResampleErrorOptions,\n VDBResampleErrorResult,\n VDBResampledGrid,\n VDBResampleFilter,\n VDBResampleOptions,\n VDBResampleDenseOptions,\n VDBResampleSource,\n} from \"./resample.js\";\nexport { vdbTransform } from \"./transform.js\";\nexport type { VDBGridTransformInput, VDBTransformSpec } from \"./transform.js\";\nexport { vdbBakeCoarseFirst } from \"./coarse-first.js\";\nexport type { VDBBakeCoarseFirstOptions } from \"./coarse-first.js\";\nexport { vdbInspect } from \"./inspect.js\";\nexport type { VDBInspectReport } from \"./inspect.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tools/nanovdb/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EACL,iBAAiB,EACjB,yBAAyB,EACzB,0BAA0B,GAC3B,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAEzE,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAElF,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAUpF,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC","sourcesContent":["/**\n * nanovdb/ — pure-TypeScript NanoVDB serializer (Phase 5, decision D3).\n *\n * Public surface for the orchestrator to re-export from the package root:\n * - `vdbBuildFromDense(values, dims, opts?)` -> a complete, valid FLOAT NanoVDB\n * grid image (flat u32 array) that the repo's proven readers accept.\n * - `writeNvdb(images, opts?)` -> a segment-format `.nvdb` file ArrayBuffer.\n * - `vdbBuildFromDenseDetailed(...)` -> image + computed metadata.\n *\n * Module map: bytes.ts (offsets + writer), tree.ts (dense -> sparse topology),\n * stats.ts (GridStats-style node stats), leaf-codec.ts (leaf value encoding —\n * the abstraction Fp8/FpN slot into next wave), serialize.ts (layout), and\n * write-nvdb.ts (file framing).\n */\n\nexport {\n vdbBuildFromDense,\n vdbBuildFromDenseDetailed,\n vdbBuildFromLeavesDetailed,\n} from \"./serialize.js\";\nexport type { VDBBuildFromDenseOptions, VDBBuildFromLeavesOptions, VDBBuiltGrid } from \"./serialize.js\";\nexport type { VDBDenseLayout } from \"./tree.js\";\nexport { writeNvdb } from \"./write-nvdb.js\";\nexport type { WriteNvdbOptions } from \"./write-nvdb.js\";\nexport type { VDBLeafCodec } from \"./leaf-codec.js\";\nexport {\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 FPN_DEFAULT_TOLERANCE,\n VDB_VEC3F_LEAF_CODEC,\n} from \"./leaf-codec.js\";\nexport { buildFromVdb, buildFromVdbDetailed } from \"./build-from-vdb.js\";\nexport type { BuildFromVdbOptions } from \"./build-from-vdb.js\";\nexport { vdbCollapseGrid, vdbQuantize, vdbQuantizeDetailed } from \"./quantize.js\";\nexport type { VDBQuantizeMode, VDBQuantizeOptions } from \"./quantize.js\";\nexport { vdbResampleGrid, vdbResampleError, vdbResampleDense } from \"./resample.js\";\nexport type {\n VDBResampleErrorOptions,\n VDBResampleErrorResult,\n VDBResampledGrid,\n VDBResampleFilter,\n VDBResampleOptions,\n VDBResampleDenseOptions,\n VDBResampleSource,\n} from \"./resample.js\";\nexport { vdbTransform } from \"./transform.js\";\nexport type { VDBGridTransformInput, VDBTransformSpec } from \"./transform.js\";\nexport { vdbBakeCoarseFirst } from \"./coarse-first.js\";\nexport type { VDBBakeCoarseFirstOptions } from \"./coarse-first.js\";\nexport { vdbInspect } from \"./inspect.js\";\nexport { vdbFloatToHalf, vdbHalfToFloat, vdbRoundToHalf } from \"./half.js\";\nexport type { VDBInspectReport } from \"./inspect.js\";\n"]}
@@ -8,10 +8,15 @@
8
8
  * Fp8 and FpN; Vec3f has its own); the leaf block is whatever remains up to
9
9
  * `mGridSize`, which correctly accounts for FpN's variable-size leaves.
10
10
  */
11
+ /** Structure and memory report of a NanoVDB grid image ({@link vdbInspect}). */
11
12
  export interface VDBInspectReport {
13
+ /** Grid value type name (`'Float'`, `'Fp8'`, `'FpN'`, `'Vec3f'`, ...; `'Unknown'` otherwise). */
12
14
  gridType: string;
15
+ /** Grid class name (`'LevelSet'`, `'FogVolume'`, `'Staggered'`, `'Unknown'`). */
13
16
  gridClass: string;
17
+ /** Active voxel count from the tree header. */
14
18
  voxelCount: number;
19
+ /** Number of nodes per level. */
15
20
  nodeCounts: {
16
21
  upper: number;
17
22
  lower: number;
@@ -20,5 +25,9 @@ export interface VDBInspectReport {
20
25
  /** Byte size of each grid section plus `total` (== mGridSize). */
21
26
  memoryBreakdown: Record<string, number>;
22
27
  }
23
- /** Produces a structural + memory report for a NanoVDB grid image. */
28
+ /**
29
+ * Produces a structural + memory report for a NanoVDB grid image.
30
+ *
31
+ * @param image The grid image (little-endian u32 words, `GridData` at word 0).
32
+ */
24
33
  export declare function vdbInspect(image: Uint32Array): VDBInspectReport;
@@ -14,7 +14,10 @@ const GRID_TYPE_NAMES = {
14
14
  1: "Float",
15
15
  2: "Double",
16
16
  6: "Vec3f",
17
+ 9: "Half",
18
+ 13: "Fp4",
17
19
  14: "Fp8",
20
+ 15: "Fp16",
18
21
  16: "FpN",
19
22
  };
20
23
  const GRID_CLASS_NAMES = {
@@ -23,7 +26,11 @@ const GRID_CLASS_NAMES = {
23
26
  2: "FogVolume",
24
27
  3: "Staggered",
25
28
  };
26
- /** Produces a structural + memory report for a NanoVDB grid image. */
29
+ /**
30
+ * Produces a structural + memory report for a NanoVDB grid image.
31
+ *
32
+ * @param image The grid image (little-endian u32 words, `GridData` at word 0).
33
+ */
27
34
  export function vdbInspect(image) {
28
35
  const view = new DataView(image.buffer, image.byteOffset, image.byteLength);
29
36
  const gridTypeId = view.getUint32(GRID_OFF_GRID_TYPE, true);
@@ -1 +1 @@
1
- {"version":3,"file":"inspect.js","sourceRoot":"","sources":["../../../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EAAE,IAAI,EAAE,KAAK,EAAE;QACzD,eAAe,EAAE;YACf,QAAQ,EAAE,SAAS;YACnB,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,WAAW;YACjB,KAAK,EAAE,YAAY;YACnB,KAAK,EAAE,YAAY;YACnB,IAAI,EAAE,WAAW;YACjB,KAAK;SACN;KACF,CAAC;AACJ,CAAC","sourcesContent":["/**\n * inspect.ts — a structural report for a NanoVDB grid image: grid type/class,\n * active voxel count, per-level node counts and a memory breakdown by section.\n * Everything is read straight from GridData/TreeData/RootData, so it works on\n * any FLOAT/Fp8/FpN/Vec3f image (ours or native `nanovdb_convert` output).\n *\n * The section sizes use the root/tile/upper/lower strides (shared by FLOAT,\n * Fp8 and FpN; Vec3f has its own); the leaf block is whatever remains up to\n * `mGridSize`, which correctly accounts for FpN's variable-size leaves.\n */\n\nimport {\n FLOAT_LAYOUT,\n GRID_TYPE_VEC3F,\n VEC3F_LAYOUT,\n GRID_OFF_GRID_CLASS,\n GRID_OFF_GRID_SIZE,\n GRID_OFF_GRID_TYPE,\n GRID_SIZE,\n ROOT_OFF_TABLE_SIZE,\n TREE_OFF_NODE_COUNT_LEAF,\n TREE_OFF_NODE_COUNT_LOWER,\n TREE_OFF_NODE_COUNT_UPPER,\n TREE_OFF_NODE_OFFSET_LEAF,\n TREE_OFF_NODE_OFFSET_ROOT,\n TREE_OFF_VOXEL_COUNT,\n TREE_SIZE,\n} from \"./bytes.js\";\n\nexport interface VDBInspectReport {\n gridType: string;\n gridClass: string;\n voxelCount: number;\n nodeCounts: { upper: number; lower: number; leaf: number };\n /** Byte size of each grid section plus `total` (== mGridSize). */\n memoryBreakdown: Record<string, number>;\n}\n\nconst GRID_TYPE_NAMES: Record<number, string> = {\n 0: \"Unknown\",\n 1: \"Float\",\n 2: \"Double\",\n 6: \"Vec3f\",\n 14: \"Fp8\",\n 16: \"FpN\",\n};\n\nconst GRID_CLASS_NAMES: Record<number, string> = {\n 0: \"Unknown\",\n 1: \"LevelSet\",\n 2: \"FogVolume\",\n 3: \"Staggered\",\n};\n\n/** Produces a structural + memory report for a NanoVDB grid image. */\nexport function vdbInspect(image: Uint32Array): VDBInspectReport {\n const view = new DataView(image.buffer, image.byteOffset, image.byteLength);\n\n const gridTypeId = view.getUint32(GRID_OFF_GRID_TYPE, true);\n const gridClassId = view.getUint32(GRID_OFF_GRID_CLASS, true);\n const total = Number(view.getBigUint64(GRID_OFF_GRID_SIZE, true));\n\n const treeOff = GRID_SIZE;\n const voxelCount = Number(view.getBigUint64(treeOff + TREE_OFF_VOXEL_COUNT, true));\n const nLeaf = view.getUint32(treeOff + TREE_OFF_NODE_COUNT_LEAF, true);\n const nLower = view.getUint32(treeOff + TREE_OFF_NODE_COUNT_LOWER, true);\n const nUpper = view.getUint32(treeOff + TREE_OFF_NODE_COUNT_UPPER, true);\n\n const rootOff = treeOff + Number(view.getBigUint64(treeOff + TREE_OFF_NODE_OFFSET_ROOT, true));\n const nTiles = view.getUint32(rootOff + ROOT_OFF_TABLE_SIZE, true);\n const leafOff = treeOff + Number(view.getBigUint64(treeOff + TREE_OFF_NODE_OFFSET_LEAF, true));\n\n // Root/tile/upper/lower strides are shared by FLOAT/Fp8/FpN; Vec3f differs.\n const L = gridTypeId === GRID_TYPE_VEC3F ? VEC3F_LAYOUT : FLOAT_LAYOUT;\n const rootSection = L.rootSize + nTiles * L.rootTileSize;\n const upperSection = nUpper * L.upperSize;\n const lowerSection = nLower * L.lowerSize;\n // Leaf block is the remainder to end-of-grid — correct even for variable-size FpN leaves.\n const leafSection = Math.max(0, total - leafOff);\n\n return {\n gridType: GRID_TYPE_NAMES[gridTypeId] ?? `type#${gridTypeId}`,\n gridClass: GRID_CLASS_NAMES[gridClassId] ?? `class#${gridClassId}`,\n voxelCount,\n nodeCounts: { upper: nUpper, lower: nLower, leaf: nLeaf },\n memoryBreakdown: {\n gridData: GRID_SIZE,\n tree: TREE_SIZE,\n root: rootSection,\n upper: upperSection,\n lower: lowerSection,\n leaf: leafSection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AS,EAAE,gBAAgB,CAAC,WAAW,CAAC,IAAI,SAAS,WAAW,EAAE;QAClE,UAAU;QACV,UAAU,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE;QACzD,eAAe,EAAE;YACf,QAAQ,EAAE,SAAS;YACnB,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,WAAW;YACjB,KAAK,EAAE,YAAY;YACnB,KAAK,EAAE,YAAY;YACnB,IAAI,EAAE,WAAW;YACjB,KAAK;SACN;KACF,CAAC;AACJ,CAAC","sourcesContent":["/**\n * inspect.ts — a structural report for a NanoVDB grid image: grid type/class,\n * active voxel count, per-level node counts and a memory breakdown by section.\n * Everything is read straight from GridData/TreeData/RootData, so it works on\n * any FLOAT/Fp8/FpN/Vec3f image (ours or native `nanovdb_convert` output).\n *\n * The section sizes use the root/tile/upper/lower strides (shared by FLOAT,\n * Fp8 and FpN; Vec3f has its own); the leaf block is whatever remains up to\n * `mGridSize`, which correctly accounts for FpN's variable-size leaves.\n */\n\nimport {\n FLOAT_LAYOUT,\n GRID_TYPE_VEC3F,\n VEC3F_LAYOUT,\n GRID_OFF_GRID_CLASS,\n GRID_OFF_GRID_SIZE,\n GRID_OFF_GRID_TYPE,\n GRID_SIZE,\n ROOT_OFF_TABLE_SIZE,\n TREE_OFF_NODE_COUNT_LEAF,\n TREE_OFF_NODE_COUNT_LOWER,\n TREE_OFF_NODE_COUNT_UPPER,\n TREE_OFF_NODE_OFFSET_LEAF,\n TREE_OFF_NODE_OFFSET_ROOT,\n TREE_OFF_VOXEL_COUNT,\n TREE_SIZE,\n} from \"./bytes.js\";\n\n/** Structure and memory report of a NanoVDB grid image ({@link vdbInspect}). */\nexport interface VDBInspectReport {\n /** Grid value type name (`'Float'`, `'Fp8'`, `'FpN'`, `'Vec3f'`, ...; `'Unknown'` otherwise). */\n gridType: string;\n /** Grid class name (`'LevelSet'`, `'FogVolume'`, `'Staggered'`, `'Unknown'`). */\n gridClass: string;\n /** Active voxel count from the tree header. */\n voxelCount: number;\n /** Number of nodes per level. */\n nodeCounts: { upper: number; lower: number; leaf: number };\n /** Byte size of each grid section plus `total` (== mGridSize). */\n memoryBreakdown: Record<string, number>;\n}\n\nconst GRID_TYPE_NAMES: Record<number, string> = {\n 0: \"Unknown\",\n 1: \"Float\",\n 2: \"Double\",\n 6: \"Vec3f\",\n 9: \"Half\",\n 13: \"Fp4\",\n 14: \"Fp8\",\n 15: \"Fp16\",\n 16: \"FpN\",\n};\n\nconst GRID_CLASS_NAMES: Record<number, string> = {\n 0: \"Unknown\",\n 1: \"LevelSet\",\n 2: \"FogVolume\",\n 3: \"Staggered\",\n};\n\n/**\n * Produces a structural + memory report for a NanoVDB grid image.\n *\n * @param image The grid image (little-endian u32 words, `GridData` at word 0).\n */\nexport function vdbInspect(image: Uint32Array): VDBInspectReport {\n const view = new DataView(image.buffer, image.byteOffset, image.byteLength);\n\n const gridTypeId = view.getUint32(GRID_OFF_GRID_TYPE, true);\n const gridClassId = view.getUint32(GRID_OFF_GRID_CLASS, true);\n const total = Number(view.getBigUint64(GRID_OFF_GRID_SIZE, true));\n\n const treeOff = GRID_SIZE;\n const voxelCount = Number(view.getBigUint64(treeOff + TREE_OFF_VOXEL_COUNT, true));\n const nLeaf = view.getUint32(treeOff + TREE_OFF_NODE_COUNT_LEAF, true);\n const nLower = view.getUint32(treeOff + TREE_OFF_NODE_COUNT_LOWER, true);\n const nUpper = view.getUint32(treeOff + TREE_OFF_NODE_COUNT_UPPER, true);\n\n const rootOff = treeOff + Number(view.getBigUint64(treeOff + TREE_OFF_NODE_OFFSET_ROOT, true));\n const nTiles = view.getUint32(rootOff + ROOT_OFF_TABLE_SIZE, true);\n const leafOff = treeOff + Number(view.getBigUint64(treeOff + TREE_OFF_NODE_OFFSET_LEAF, true));\n\n // Root/tile/upper/lower strides are shared by FLOAT/Fp8/FpN; Vec3f differs.\n const L = gridTypeId === GRID_TYPE_VEC3F ? VEC3F_LAYOUT : FLOAT_LAYOUT;\n const rootSection = L.rootSize + nTiles * L.rootTileSize;\n const upperSection = nUpper * L.upperSize;\n const lowerSection = nLower * L.lowerSize;\n // Leaf block is the remainder to end-of-grid — correct even for variable-size FpN leaves.\n const leafSection = Math.max(0, total - leafOff);\n\n return {\n gridType: GRID_TYPE_NAMES[gridTypeId] ?? `type#${gridTypeId}`,\n gridClass: GRID_CLASS_NAMES[gridClassId] ?? `class#${gridClassId}`,\n voxelCount,\n nodeCounts: { upper: nUpper, lower: nLower, leaf: nLeaf },\n memoryBreakdown: {\n gridData: GRID_SIZE,\n tree: TREE_SIZE,\n root: rootSection,\n upper: upperSection,\n lower: lowerSection,\n leaf: leafSection,\n total,\n },\n };\n}\n"]}
@@ -17,6 +17,8 @@
17
17
  * quantization (`LeafData<Fp4|Fp8|Fp16>`).
18
18
  * - {@link vdbMakeFpNLeafCodec} — variable bit-width (`LeafData<FpN>`); a
19
19
  * per-leaf oracle picks the smallest of 1/2/4/8/16 bits meeting a tolerance.
20
+ * - {@link VDB_HALF_LEAF_CODEC} — 512 raw IEEE binary16 values
21
+ * (`LeafData<Half>`, K7.H); tiles, background and min/max are binary16 too.
20
22
  *
21
23
  * ## Encode authority
22
24
  *
@@ -45,7 +47,9 @@ export interface LeafPlan {
45
47
  /** Total byte size of this leaf (header + value table). */
46
48
  readonly byteSize: number;
47
49
  }
50
+ /** Encodes the leaves and constants of one NanoVDB value type (Float, Fp4, Fp8, Fp16, FpN, Vec3f). */
48
51
  export interface VDBLeafCodec {
52
+ /** The grid type's node layout (strides and offsets) that the writer places nodes with. */
49
53
  readonly layout: GridTypeLayout;
50
54
  /** Scalars per value: 1 (default) or 3 (Vec3f). */
51
55
  readonly components?: 1 | 3;
@@ -53,19 +57,48 @@ export interface VDBLeafCodec {
53
57
  * Computes a leaf's encoding plan (its byte size, and for FpN the chosen
54
58
  * bit-width) from its 512 values. Called once before layout so variable-size
55
59
  * (FpN) leaves can be placed at cumulative offsets.
60
+ *
61
+ * @param values The leaf's 512 values in the leaf's storage order.
56
62
  */
57
63
  planLeaf(values: Float32Array): LeafPlan;
58
64
  /**
59
65
  * Writes one leaf's entire block — bbox, `bbox_dif_and_flags`, value mask,
60
66
  * value table and per-leaf stats — into the image at absolute byte offset
61
67
  * `leafOff`. `plan` is the value returned by {@link planLeaf} for this leaf.
68
+ *
69
+ * @param w The image writer.
70
+ * @param leafOff Absolute byte offset of the leaf in the image.
71
+ * @param leaf The leaf's origin, values, value mask and active-value statistics.
72
+ * @param plan The plan {@link planLeaf} returned for this leaf.
62
73
  */
63
74
  encodeLeaf(w: GridImageWriter, leafOff: number, leaf: EncodableLeaf, plan: LeafPlan): void;
64
- /** Writes a single constant value (an internal-node tile / background). */
75
+ /**
76
+ * Writes a single value of the grid's value type: an internal-node tile, the
77
+ * background, or a root/upper/lower min/max statistic of a scalar grid.
78
+ *
79
+ * @param w The image writer.
80
+ * @param off Absolute byte offset to write at.
81
+ * @param value The constant: a number, or `[x, y, z]` for a Vec3f codec.
82
+ */
65
83
  writeConstant(w: GridImageWriter, off: number, value: TileValue): void;
84
+ /**
85
+ * Rounds a scalar to what the grid stores (Half: the nearest binary16). When
86
+ * present, `vdbBuildFromLeavesDetailed` passes every leaf value, tile value
87
+ * and the background through it before computing statistics, so min/max/ave
88
+ * describe the stored values (as NanoVDB's GridStats does on a Half grid).
89
+ */
90
+ readonly roundValue?: (value: number) => number;
66
91
  }
67
92
  /** FLOAT leaf codec: 512 raw f32 values, f32 stats. */
68
93
  export declare const VDB_FLOAT_LEAF_CODEC: VDBLeafCodec;
94
+ /**
95
+ * Half leaf codec (`LeafData<Half>`, NanoVDB 13.2): 512 raw IEEE binary16
96
+ * values, binary16 min/max and f32 ave/stddev. Values convert with
97
+ * {@link vdbFloatToHalf} (NanoVDB `math::FloatToHalf`, round to nearest even,
98
+ * overflow to infinity), as `tools::createNanoGrid<FloatGrid, Half>` does.
99
+ * `roundValue` makes the build's statistics describe the stored halves.
100
+ */
101
+ export declare const VDB_HALF_LEAF_CODEC: VDBLeafCodec;
69
102
  /**
70
103
  * Vec3f leaf codec (K4.2): 512 x 3 f32 values (xyz interleaved in
71
104
  * `leaf.values`), Vec3f min/max and f32 ave/stddev of the squared lengths
@@ -76,6 +109,7 @@ export declare const VDB_VEC3F_LEAF_CODEC: VDBLeafCodec;
76
109
  export declare function writeVec3StatsBlock(w: GridImageWriter, base: number, offMin: number, offMax: number, offAve: number, offStdDev: number, stats: StatsAccumulator): void;
77
110
  /** Fp4: fixed 4-bit codes (`LeafData<Fp4>`, 16 levels per leaf). */
78
111
  export declare const VDB_FP4_LEAF_CODEC: VDBLeafCodec;
112
+ /** Fp8: fixed 8-bit codes (`LeafData<Fp8>`). */
79
113
  export declare const VDB_FP8_LEAF_CODEC: VDBLeafCodec;
80
114
  /** Fp16: fixed 16-bit codes (`LeafData<Fp16>`). */
81
115
  export declare const VDB_FP16_LEAF_CODEC: VDBLeafCodec;
@@ -17,6 +17,8 @@
17
17
  * quantization (`LeafData<Fp4|Fp8|Fp16>`).
18
18
  * - {@link vdbMakeFpNLeafCodec} — variable bit-width (`LeafData<FpN>`); a
19
19
  * per-leaf oracle picks the smallest of 1/2/4/8/16 bits meeting a tolerance.
20
+ * - {@link VDB_HALF_LEAF_CODEC} — 512 raw IEEE binary16 values
21
+ * (`LeafData<Half>`, K7.H); tiles, background and min/max are binary16 too.
20
22
  *
21
23
  * ## Encode authority
22
24
  *
@@ -30,8 +32,9 @@
30
32
  * at global bit `n*bits`, identical to the reader's word/shift addressing.
31
33
  */
32
34
  import { VDBToolsError } from "../errors.js";
33
- import { FLOAT_LAYOUT, VEC3F_LAYOUT, FP4_LAYOUT, FP8_LAYOUT, FP16_LAYOUT, FP_LEAF_HEADER_SIZE, FPN_LAYOUT, LEAF_FLAG_HAS_BBOX, LEAF_OFF_BBOX_DIF_AND_FLAGS, LEAF_OFF_BBOX_MIN, LEAF_OFF_FP_CODES, LEAF_OFF_FP_MINIMUM, LEAF_OFF_FP_QUANTUM, LEAF_OFF_FP_STAT_AVG, LEAF_OFF_FP_STAT_DEV, LEAF_OFF_FP_STAT_MAX, LEAF_OFF_FP_STAT_MIN, LEAF_TABLE_COUNT, NODE_FLAG_STATS, } from "./bytes.js";
34
- import { Vec3StatsAccumulator } from "./stats.js";
35
+ import { FLOAT_LAYOUT, VEC3F_LAYOUT, FP4_LAYOUT, FP8_LAYOUT, FP16_LAYOUT, FP_LEAF_HEADER_SIZE, FPN_LAYOUT, HALF_LAYOUT, LEAF_FLAG_HAS_BBOX, LEAF_OFF_BBOX_DIF_AND_FLAGS, LEAF_OFF_BBOX_MIN, LEAF_OFF_FP_CODES, LEAF_OFF_FP_MINIMUM, LEAF_OFF_FP_QUANTUM, LEAF_OFF_FP_STAT_AVG, LEAF_OFF_FP_STAT_DEV, LEAF_OFF_FP_STAT_MAX, LEAF_OFF_FP_STAT_MIN, LEAF_TABLE_COUNT, NODE_FLAG_STATS, } from "./bytes.js";
36
+ import { vdbFloatToHalf, vdbRoundToHalf } from "./half.js";
37
+ import { STATS_FLOAT_MAX, STATS_HALF_MAX, Vec3StatsAccumulator } from "./stats.js";
35
38
  /** A scalar codec's constant: tiles and backgrounds of scalar grids are numbers. */
36
39
  function scalar(value) {
37
40
  if (typeof value !== "number")
@@ -78,8 +81,8 @@ export const VDB_FLOAT_LEAF_CODEC = {
78
81
  // Stats block. For an all-inactive leaf the accumulator is empty; write
79
82
  // zeros, matching "no active values".
80
83
  const s = leaf.stats;
81
- w.setF32(leafOff + L.leafOffMin, s.isEmpty ? 0 : s.min);
82
- w.setF32(leafOff + L.leafOffMax, s.isEmpty ? 0 : s.max);
84
+ w.setF32(leafOff + L.leafOffMin, s.storedMin(STATS_FLOAT_MAX));
85
+ w.setF32(leafOff + L.leafOffMax, s.storedMax(STATS_FLOAT_MAX));
83
86
  w.setF32(leafOff + L.leafOffAve, s.average);
84
87
  w.setF32(leafOff + L.leafOffStdDev, s.stdDev);
85
88
  },
@@ -88,6 +91,38 @@ export const VDB_FLOAT_LEAF_CODEC = {
88
91
  },
89
92
  };
90
93
  // ---------------------------------------------------------------------------
94
+ // Half (K7.H)
95
+ // ---------------------------------------------------------------------------
96
+ /**
97
+ * Half leaf codec (`LeafData<Half>`, NanoVDB 13.2): 512 raw IEEE binary16
98
+ * values, binary16 min/max and f32 ave/stddev. Values convert with
99
+ * {@link vdbFloatToHalf} (NanoVDB `math::FloatToHalf`, round to nearest even,
100
+ * overflow to infinity), as `tools::createNanoGrid<FloatGrid, Half>` does.
101
+ * `roundValue` makes the build's statistics describe the stored halves.
102
+ */
103
+ export const VDB_HALF_LEAF_CODEC = {
104
+ layout: HALF_LAYOUT,
105
+ roundValue: vdbRoundToHalf,
106
+ planLeaf() {
107
+ return { byteSize: HALF_LAYOUT.leafSize };
108
+ },
109
+ encodeLeaf(w, leafOff, leaf) {
110
+ writeLeafHeader(w, leafOff, leaf, NODE_FLAG_STATS);
111
+ const L = HALF_LAYOUT;
112
+ const values = leaf.values;
113
+ for (let n = 0; n < LEAF_TABLE_COUNT; n++)
114
+ w.setU16(leafOff + L.leafOffTable + n * 2, vdbFloatToHalf(values[n]));
115
+ const s = leaf.stats;
116
+ w.setU16(leafOff + L.leafOffMin, vdbFloatToHalf(s.storedMin(STATS_HALF_MAX)));
117
+ w.setU16(leafOff + L.leafOffMax, vdbFloatToHalf(s.storedMax(STATS_HALF_MAX)));
118
+ w.setF32(leafOff + L.leafOffAve, s.average);
119
+ w.setF32(leafOff + L.leafOffStdDev, s.stdDev);
120
+ },
121
+ writeConstant(w, off, value) {
122
+ w.setU16(off, vdbFloatToHalf(scalar(value)));
123
+ },
124
+ };
125
+ // ---------------------------------------------------------------------------
91
126
  // Vec3f
92
127
  // ---------------------------------------------------------------------------
93
128
  /** Writes a Vec3f (3 x f32) at `off`. */
@@ -246,6 +281,7 @@ function makeFixedLeafCodec(layout, bits) {
246
281
  }
247
282
  /** Fp4: fixed 4-bit codes (`LeafData<Fp4>`, 16 levels per leaf). */
248
283
  export const VDB_FP4_LEAF_CODEC = makeFixedLeafCodec(FP4_LAYOUT, 4);
284
+ /** Fp8: fixed 8-bit codes (`LeafData<Fp8>`). */
249
285
  export const VDB_FP8_LEAF_CODEC = makeFixedLeafCodec(FP8_LAYOUT, 8);
250
286
  /** Fp16: fixed 16-bit codes (`LeafData<Fp16>`). */
251
287
  export const VDB_FP16_LEAF_CODEC = makeFixedLeafCodec(FP16_LAYOUT, 16);
@@ -1 +1 @@
1
- {"version":3,"file":"leaf-codec.js","sourceRoot":"","sources":["../../../src/tools/nanovdb/leaf-codec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,UAAU,EACV,WAAW,EACX,mBAAmB,EACnB,UAAU,EAEV,kBAAkB,EAClB,2BAA2B,EAC3B,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,gBAAgB,EAChB,eAAe,GAChB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAyB,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAqCzE,oFAAoF;AACpF,SAAS,MAAM,CAAC,KAAgB;IAC9B,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,MAAM,IAAI,aAAa,CAAC,gBAAgB,EAAE,6CAA6C,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC3I,OAAO,KAAK,CAAC;AACf,CAAC;AAED,8EAA8E;AAC9E,kFAAkF;AAClF,8EAA8E;AAE9E,SAAS,SAAS,CAAC,CAAS;IAC1B,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAA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ACJ,CAAC","sourcesContent":["/**\n * leaf-codec.ts — the leaf value-table encoder abstraction.\n *\n * The leaf is the only block whose *value representation* varies by grid type:\n * FLOAT stores 512 plain f32s; Fp8/FpN store a per-leaf (min, quantum) pair plus\n * a packed bit-stream of quantized codes. Everything else about a grid image\n * (topology, masks, internal-node tables, stats, bbox, GridData) is identical\n * across those types — the internal-node/root tiles and background stay plain\n * f32 even for quantized grids (verified against native fp8/fpn fixtures). So the\n * serializer is parameterised over a {@link VDBLeafCodec}: `serialize.ts` lays out\n * the common blocks and hands each leaf to the codec, which owns the full leaf\n * write (bbox, flags, value mask, value table and per-leaf stats).\n *\n * Three codecs ship:\n * - {@link VDB_FLOAT_LEAF_CODEC} — 512 raw f32 values + f32 stats.\n * - {@link VDB_FP4_LEAF_CODEC} / {@link VDB_FP8_LEAF_CODEC} / {@link VDB_FP16_LEAF_CODEC} — fixed 4/8/16-bit\n * quantization (`LeafData<Fp4|Fp8|Fp16>`).\n * - {@link vdbMakeFpNLeafCodec} — variable bit-width (`LeafData<FpN>`); a\n * per-leaf oracle picks the smallest of 1/2/4/8/16 bits meeting a tolerance.\n *\n * ## Encode authority\n *\n * The quantization mirrors `nanovdb::tools::CreateNanoGrid` (NanoVDB.h\n * `LeafFnBase`/`LeafData<Fp8|FpN>` + CreateNanoGrid.h `processLeafs`) and must\n * satisfy the repo's proven decoders (`read-value.ts` `leafFp*ReadFloat` and\n * `pnanovdb.wgsl`). Per-leaf `mMinimum`/`mQuantum` = min / (max-min)/((1<<bits)-1)\n * over ALL 512 values (active and inactive). A code is\n * `floor(encode*(v-min) + 0.5)` — round-to-nearest, matching native's\n * dithering-off `DitherLUT` (constant 0.5). Codes are packed LSB-first, value `n`\n * at global bit `n*bits`, identical to the reader's word/shift addressing.\n */\n\nimport { VDBToolsError } from \"../errors.js\";\nimport {\n FLOAT_LAYOUT,\n VEC3F_LAYOUT,\n FP4_LAYOUT,\n FP8_LAYOUT,\n FP16_LAYOUT,\n FP_LEAF_HEADER_SIZE,\n FPN_LAYOUT,\n type GridTypeLayout,\n LEAF_FLAG_HAS_BBOX,\n LEAF_OFF_BBOX_DIF_AND_FLAGS,\n LEAF_OFF_BBOX_MIN,\n LEAF_OFF_FP_CODES,\n LEAF_OFF_FP_MINIMUM,\n LEAF_OFF_FP_QUANTUM,\n LEAF_OFF_FP_STAT_AVG,\n LEAF_OFF_FP_STAT_DEV,\n LEAF_OFF_FP_STAT_MAX,\n LEAF_OFF_FP_STAT_MIN,\n LEAF_TABLE_COUNT,\n NODE_FLAG_STATS,\n} from \"./bytes.js\";\nimport type { GridImageWriter } from \"./bytes.js\";\nimport { type StatsAccumulator, Vec3StatsAccumulator } from \"./stats.js\";\nimport type { TileValue } from \"./tree.js\";\n\n/** The leaf data a codec needs: origin, all 512 values, mask, active-value stats. */\nexport interface EncodableLeaf {\n origin: [number, number, number];\n values: Float32Array;\n valueMask: Uint32Array;\n stats: StatsAccumulator;\n}\n\n/** Per-leaf encoding plan, computed once by `planLeaf` and reused by `encodeLeaf`. */\nexport interface LeafPlan {\n /** Total byte size of this leaf (header + value table). */\n readonly byteSize: number;\n}\n\nexport interface VDBLeafCodec {\n readonly layout: GridTypeLayout;\n /** Scalars per value: 1 (default) or 3 (Vec3f). */\n readonly components?: 1 | 3;\n /**\n * Computes a leaf's encoding plan (its byte size, and for FpN the chosen\n * bit-width) from its 512 values. Called once before layout so variable-size\n * (FpN) leaves can be placed at cumulative offsets.\n */\n planLeaf(values: Float32Array): LeafPlan;\n /**\n * Writes one leaf's entire block — bbox, `bbox_dif_and_flags`, value mask,\n * value table and per-leaf stats — into the image at absolute byte offset\n * `leafOff`. `plan` is the value returned by {@link planLeaf} for this leaf.\n */\n encodeLeaf(w: GridImageWriter, leafOff: number, leaf: EncodableLeaf, plan: LeafPlan): void;\n /** Writes a single constant value (an internal-node tile / background). */\n writeConstant(w: GridImageWriter, off: number, value: TileValue): void;\n}\n\n/** A scalar codec's constant: tiles and backgrounds of scalar grids are numbers. */\nfunction scalar(value: TileValue): number {\n if (typeof value !== \"number\") throw new VDBToolsError(\"VDB_BAD_OPTION\", `leaf codec: expected a scalar value, got [${value.join(\", \")}]`);\n return value;\n}\n\n// ---------------------------------------------------------------------------\n// Shared leaf-header write (bbox + dif/flags + value mask) — common to all codecs\n// ---------------------------------------------------------------------------\n\nfunction clampByte(v: number): number {\n return v < 0 ? 0 : v > 255 ? 255 : v;\n}\n\n/** Writes bbox_min, bbox_dif_and_flags (with `flagsByte` in the high byte) and\n * the 512-bit value mask. Returns nothing; the codec then writes its table. */\nfunction writeLeafHeader(\n w: GridImageWriter,\n leafOff: number,\n leaf: EncodableLeaf,\n flagsByte: number,\n): void {\n const s = leaf.stats;\n const bmin = s.isEmpty ? leaf.origin : s.bboxMin;\n const bmax = s.isEmpty ? leaf.origin : s.bboxMax;\n w.setI32(leafOff + LEAF_OFF_BBOX_MIN, bmin[0]);\n w.setI32(leafOff + LEAF_OFF_BBOX_MIN + 4, bmin[1]);\n w.setI32(leafOff + LEAF_OFF_BBOX_MIN + 8, bmin[2]);\n const difX = clampByte(bmax[0] - bmin[0]);\n const difY = clampByte(bmax[1] - bmin[1]);\n const difZ = clampByte(bmax[2] - bmin[2]);\n w.setU32(\n leafOff + LEAF_OFF_BBOX_DIF_AND_FLAGS,\n (difX | (difY << 8) | (difZ << 16) | (flagsByte << 24)) >>> 0,\n );\n w.setMaskWords(leafOff + 16, leaf.valueMask);\n}\n\n// ---------------------------------------------------------------------------\n// FLOAT\n// ---------------------------------------------------------------------------\n\n/** FLOAT leaf codec: 512 raw f32 values, f32 stats. */\nexport const VDB_FLOAT_LEAF_CODEC: VDBLeafCodec = {\n layout: FLOAT_LAYOUT,\n planLeaf() {\n return { byteSize: FLOAT_LAYOUT.leafSize };\n },\n encodeLeaf(w, leafOff, leaf) {\n writeLeafHeader(w, leafOff, leaf, NODE_FLAG_STATS);\n const L = FLOAT_LAYOUT;\n const values = leaf.values;\n for (let n = 0; n < LEAF_TABLE_COUNT; n++) {\n w.setF32(leafOff + L.leafOffTable + n * 4, values[n]!);\n }\n // Stats block. For an all-inactive leaf the accumulator is empty; write\n // zeros, matching \"no active values\".\n const s = leaf.stats;\n w.setF32(leafOff + L.leafOffMin, s.isEmpty ? 0 : s.min);\n w.setF32(leafOff + L.leafOffMax, s.isEmpty ? 0 : s.max);\n w.setF32(leafOff + L.leafOffAve, s.average);\n w.setF32(leafOff + L.leafOffStdDev, s.stdDev);\n },\n writeConstant(w, off, value) {\n w.setF32(off, scalar(value));\n },\n};\n\n// ---------------------------------------------------------------------------\n// Vec3f\n// ---------------------------------------------------------------------------\n\n/** Writes a Vec3f (3 x f32) at `off`. */\nfunction writeVec3(w: GridImageWriter, off: number, v: readonly number[]): void {\n w.setF32(off, v[0]!);\n w.setF32(off + 4, v[1]!);\n w.setF32(off + 8, v[2]!);\n}\n\n/**\n * Vec3f leaf codec (K4.2): 512 x 3 f32 values (xyz interleaved in\n * `leaf.values`), Vec3f min/max and f32 ave/stddev of the squared lengths\n * (NanoVDB `Stats<Vec3f, 1>`, see {@link Vec3StatsAccumulator}).\n */\nexport const VDB_VEC3F_LEAF_CODEC: VDBLeafCodec = {\n layout: VEC3F_LAYOUT,\n components: 3,\n planLeaf() {\n return { byteSize: VEC3F_LAYOUT.leafSize };\n },\n encodeLeaf(w, leafOff, leaf) {\n writeLeafHeader(w, leafOff, leaf, NODE_FLAG_STATS);\n const L = VEC3F_LAYOUT;\n const values = leaf.values;\n for (let i = 0; i < LEAF_TABLE_COUNT * 3; i++) w.setF32(leafOff + L.leafOffTable + i * 4, values[i]!);\n writeVec3StatsBlock(w, leafOff, L.leafOffMin, L.leafOffMax, L.leafOffAve, L.leafOffStdDev, leaf.stats);\n },\n writeConstant(w, off, value) {\n if (typeof value === \"number\") throw new VDBToolsError(\"VDB_BAD_OPTION\", `Vec3f codec: expected a vector value, got ${value}`);\n writeVec3(w, off, value);\n },\n};\n\n/** Writes a Vec3f node's stats block: Vec3f min/max (zeros when empty), f32 ave/stddev. */\nexport function writeVec3StatsBlock(\n w: GridImageWriter,\n base: number,\n offMin: number,\n offMax: number,\n offAve: number,\n offStdDev: number,\n stats: StatsAccumulator,\n): void {\n const empty = stats.isEmpty || !(stats instanceof Vec3StatsAccumulator);\n writeVec3(w, base + offMin, empty ? [0, 0, 0] : (stats as Vec3StatsAccumulator).minVec);\n writeVec3(w, base + offMax, empty ? [0, 0, 0] : (stats as Vec3StatsAccumulator).maxVec);\n w.setF32(base + offAve, stats.average);\n w.setF32(base + offStdDev, stats.stdDev);\n}\n\n// ---------------------------------------------------------------------------\n// Quantized (Fp8 / FpN) shared helpers\n// ---------------------------------------------------------------------------\n\nconst fround = Math.fround;\n\n/** Min and max over all 512 leaf values (the affine origin for quantization). */\nfunction leafMinMax(values: Float32Array): { min: number; max: number } {\n let min = Infinity;\n let max = -Infinity;\n for (let n = 0; n < LEAF_TABLE_COUNT; n++) {\n const v = values[n]!;\n if (v < min) min = v;\n if (v > max) max = v;\n }\n return { min, max };\n}\n\n/** `floor(encode*(v-min) + 0.5)` in float32, clamped to `[0, mask]`.\n * Matches native `uint(encode*(v-min) + 0.5f)` with dithering disabled. */\nfunction quantizeF32(v: number, min: number, encode: number, mask: number): number {\n const code = Math.floor(fround(fround(encode * fround(v - min)) + 0.5));\n return code < 0 ? 0 : code > mask ? mask : code;\n}\n\n/** `floor(encode*(v-min) + 0.5)` in double, clamped — the 16-bit FpN path. */\nfunction quantizeF64(v: number, min: number, encode: number, mask: number): number {\n const code = Math.floor(encode * (v - min) + 0.5);\n return code < 0 ? 0 : code > mask ? mask : code;\n}\n\n/** Writes mMinimum, mQuantum (f32) and the four u16 quantized statistics. */\nfunction writeFpHeaderStats(\n w: GridImageWriter,\n leafOff: number,\n min: number,\n quantum: number,\n stats: StatsAccumulator,\n): void {\n w.setF32(leafOff + LEAF_OFF_FP_MINIMUM, min);\n w.setF32(leafOff + LEAF_OFF_FP_QUANTUM, quantum);\n // Quantized active-value statistics (uint16), per LeafFnBase::set{Min,Max,Avg,Dev}.\n const qInv = quantum > 0 ? 1 / quantum : 0;\n const q16 = (x: number): number => {\n const c = Math.floor(x + 0.5);\n return c < 0 ? 0 : c > 0xffff ? 0xffff : c;\n };\n if (stats.isEmpty) {\n w.setU16(leafOff + LEAF_OFF_FP_STAT_MIN, 0);\n w.setU16(leafOff + LEAF_OFF_FP_STAT_MAX, 0);\n w.setU16(leafOff + LEAF_OFF_FP_STAT_AVG, 0);\n w.setU16(leafOff + LEAF_OFF_FP_STAT_DEV, 0);\n return;\n }\n w.setU16(leafOff + LEAF_OFF_FP_STAT_MIN, q16((stats.min - min) * qInv));\n w.setU16(leafOff + LEAF_OFF_FP_STAT_MAX, q16((stats.max - min) * qInv));\n w.setU16(leafOff + LEAF_OFF_FP_STAT_AVG, q16((stats.average - min) * qInv));\n w.setU16(leafOff + LEAF_OFF_FP_STAT_DEV, q16(stats.stdDev * qInv));\n}\n\n/**\n * Packs 512 codes at `bits` bits/value, LSB-first, into the image at\n * `leafOff + 96`. Value `n` occupies global bit range `[n*bits, n*bits+bits)`,\n * exactly what `leafFpReadFloat`'s word/shift addressing reads back.\n */\nfunction packCodes(\n w: GridImageWriter,\n leafOff: number,\n bits: number,\n codeAt: (n: number) => number,\n): void {\n const base = leafOff + LEAF_OFF_FP_CODES;\n const bytes = w.bytes;\n if (bits === 8) {\n for (let n = 0; n < LEAF_TABLE_COUNT; n++) bytes[base + n] = codeAt(n);\n return;\n }\n if (bits === 16) {\n for (let n = 0; n < LEAF_TABLE_COUNT; n++) {\n const c = codeAt(n);\n bytes[base + 2 * n] = c & 0xff;\n bytes[base + 2 * n + 1] = (c >>> 8) & 0xff;\n }\n return;\n }\n // 1/2/4 bits: sub-byte packing (buffer is zero-initialised, so OR in).\n for (let n = 0; n < LEAF_TABLE_COUNT; n++) {\n const c = codeAt(n);\n let g = n * bits;\n for (let b = 0; b < bits; b++) {\n if ((c >>> b) & 1) bytes[base + (g >>> 3)]! |= 1 << (g & 7);\n g++;\n }\n }\n}\n\n// ---------------------------------------------------------------------------\n// Fp4 / Fp8 / Fp16 — fixed bit width\n// ---------------------------------------------------------------------------\n\nfunction makeFixedLeafCodec(layout: GridTypeLayout, bits: 4 | 8 | 16): VDBLeafCodec {\n const mask = (1 << bits) - 1;\n return {\n layout,\n planLeaf() {\n return { byteSize: layout.leafSize };\n },\n encodeLeaf(w, leafOff, leaf) {\n writeLeafHeader(w, leafOff, leaf, LEAF_FLAG_HAS_BBOX);\n const { min, max } = leafMinMax(leaf.values);\n const values = leaf.values;\n if (bits === 16) {\n // Same arithmetic as FpN's 16-bit path: double encode, f32-stored quantum.\n const range = max - min;\n writeFpHeaderStats(w, leafOff, min, range > 0 ? range / mask : 0, leaf.stats);\n const encode = range > 0 ? mask / range : 0;\n packCodes(w, leafOff, 16, (n) => quantizeF64(values[n]!, min, encode, mask));\n return;\n }\n const range = fround(max - min);\n const quantum = range > 0 ? fround(range / mask) : 0;\n writeFpHeaderStats(w, leafOff, min, quantum, leaf.stats);\n const encode = range > 0 ? fround(mask / range) : 0;\n packCodes(w, leafOff, bits, (n) => quantizeF32(values[n]!, min, encode, mask));\n },\n writeConstant(w, off, value) {\n w.setF32(off, scalar(value));\n },\n };\n}\n\n/** Fp4: fixed 4-bit codes (`LeafData<Fp4>`, 16 levels per leaf). */\nexport const VDB_FP4_LEAF_CODEC: VDBLeafCodec = makeFixedLeafCodec(FP4_LAYOUT, 4);\nexport const VDB_FP8_LEAF_CODEC: VDBLeafCodec = makeFixedLeafCodec(FP8_LAYOUT, 8);\n/** Fp16: fixed 16-bit codes (`LeafData<Fp16>`). */\nexport const VDB_FP16_LEAF_CODEC: VDBLeafCodec = makeFixedLeafCodec(FP16_LAYOUT, 16);\n\n// ---------------------------------------------------------------------------\n// FpN — variable bit-width chosen per leaf by an absolute-difference oracle\n// ---------------------------------------------------------------------------\n\n/** Native's default absolute tolerance for a FogVolume (`AbsDiff::init`). */\nexport const FPN_DEFAULT_TOLERANCE = 0.01;\n\nconst LOG_BITS_MAX = 4; // logBitWidth in [0,4] -> 1,2,4,8,16 bits\n\n/**\n * Picks the smallest logBitWidth (0..4 -> 1,2,4,8,16 bits) whose float32 encode\n * keeps every one of the 512 values within `tolerance` of its dequantized\n * approximation — the exact loop in `CreateNanoGrid::preProcess<FpN>`.\n */\nfunction chooseFpNLogBits(values: Float32Array, min: number, max: number, tolerance: number): number {\n const range = fround(max - min);\n if (!(range > 0)) return 0; // constant leaf -> 1 bit (quantum 0)\n for (let logBits = 0; logBits < LOG_BITS_MAX; logBits++) {\n const mask = (1 << (1 << logBits)) - 1;\n const encode = fround(mask / range);\n const decode = fround(range / mask);\n let ok = true;\n for (let n = 0; n < LEAF_TABLE_COUNT; n++) {\n const exact = values[n]!;\n const code = quantizeF32(exact, min, encode, mask);\n const approx = fround(fround(code * decode) + min);\n if (fround(Math.abs(exact - approx)) > tolerance) {\n ok = false;\n break;\n }\n }\n if (ok) return logBits;\n }\n return LOG_BITS_MAX;\n}\n\ninterface FpNPlan extends LeafPlan {\n readonly logBits: number;\n}\n\n/** Builds an FpN codec for a given absolute tolerance (default: native's 0.01). */\nexport function vdbMakeFpNLeafCodec(tolerance: number = FPN_DEFAULT_TOLERANCE): VDBLeafCodec {\n return {\n layout: FPN_LAYOUT,\n planLeaf(values): FpNPlan {\n const { min, max } = leafMinMax(values);\n const logBits = chooseFpNLogBits(values, min, max, tolerance);\n const bits = 1 << logBits;\n return { byteSize: FP_LEAF_HEADER_SIZE + bits * 64, logBits };\n },\n encodeLeaf(w, leafOff, leaf, plan) {\n const logBits = (plan as FpNPlan).logBits;\n const bits = 1 << logBits;\n writeLeafHeader(w, leafOff, leaf, (logBits << 5) | LEAF_FLAG_HAS_BBOX);\n const { min, max } = leafMinMax(leaf.values);\n const range = max - min;\n const mask = (1 << bits) - 1;\n const quantum = range > 0 ? (bits >= 16 ? range / mask : fround(range / mask)) : 0;\n writeFpHeaderStats(w, leafOff, min, quantum, leaf.stats);\n const values = leaf.values;\n if (bits >= 16) {\n const encode = range > 0 ? 65535 / range : 0;\n packCodes(w, leafOff, bits, (n) => quantizeF64(values[n]!, min, encode, mask));\n } else {\n const encode = range > 0 ? fround(mask / fround(range)) : 0;\n packCodes(w, leafOff, bits, (n) => quantizeF32(values[n]!, min, encode, mask));\n }\n },\n writeConstant(w, off, value) {\n w.setF32(off, scalar(value));\n },\n };\n}\n"]}
1
+ {"version":3,"file":"leaf-codec.js","sourceRoot":"","sources":["../../../src/tools/nanovdb/leaf-codec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,UAAU,EACV,WAAW,EACX,mBAAmB,EACnB,UAAU,EAEV,WAAW,EACX,kBAAkB,EAClB,2BAA2B,EAC3B,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,gBAAgB,EAChB,eAAe,GAChB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,cAAc,EAAyB,oBAAoB,EAAE,MAAM,YAAY,CAAC;AA4D1G,oFAAoF;AACpF,SAAS,MAAM,CAAC,KAAgB;IAC9B,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,MAAM,IAAI,aAAa,CAAC,gBAAgB,EAAE,6CAA6C,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC3I,OAAO,KAAK,CAAC;AACf,CAAC;AAED,8EAA8E;AAC9E,kFAAkF;AAClF,8EAA8E;AAE9E,SAAS,SAAS,CAAC,CAAS;IAC1B,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG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AAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAC/B,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/**\n * leaf-codec.ts — the leaf value-table encoder abstraction.\n *\n * The leaf is the only block whose *value representation* varies by grid type:\n * FLOAT stores 512 plain f32s; Fp8/FpN store a per-leaf (min, quantum) pair plus\n * a packed bit-stream of quantized codes. Everything else about a grid image\n * (topology, masks, internal-node tables, stats, bbox, GridData) is identical\n * across those types — the internal-node/root tiles and background stay plain\n * f32 even for quantized grids (verified against native fp8/fpn fixtures). So the\n * serializer is parameterised over a {@link VDBLeafCodec}: `serialize.ts` lays out\n * the common blocks and hands each leaf to the codec, which owns the full leaf\n * write (bbox, flags, value mask, value table and per-leaf stats).\n *\n * Three codecs ship:\n * - {@link VDB_FLOAT_LEAF_CODEC} — 512 raw f32 values + f32 stats.\n * - {@link VDB_FP4_LEAF_CODEC} / {@link VDB_FP8_LEAF_CODEC} / {@link VDB_FP16_LEAF_CODEC} — fixed 4/8/16-bit\n * quantization (`LeafData<Fp4|Fp8|Fp16>`).\n * - {@link vdbMakeFpNLeafCodec} — variable bit-width (`LeafData<FpN>`); a\n * per-leaf oracle picks the smallest of 1/2/4/8/16 bits meeting a tolerance.\n * - {@link VDB_HALF_LEAF_CODEC} — 512 raw IEEE binary16 values\n * (`LeafData<Half>`, K7.H); tiles, background and min/max are binary16 too.\n *\n * ## Encode authority\n *\n * The quantization mirrors `nanovdb::tools::CreateNanoGrid` (NanoVDB.h\n * `LeafFnBase`/`LeafData<Fp8|FpN>` + CreateNanoGrid.h `processLeafs`) and must\n * satisfy the repo's proven decoders (`read-value.ts` `leafFp*ReadFloat` and\n * `pnanovdb.wgsl`). Per-leaf `mMinimum`/`mQuantum` = min / (max-min)/((1<<bits)-1)\n * over ALL 512 values (active and inactive). A code is\n * `floor(encode*(v-min) + 0.5)` — round-to-nearest, matching native's\n * dithering-off `DitherLUT` (constant 0.5). Codes are packed LSB-first, value `n`\n * at global bit `n*bits`, identical to the reader's word/shift addressing.\n */\n\nimport { VDBToolsError } from \"../errors.js\";\nimport {\n FLOAT_LAYOUT,\n VEC3F_LAYOUT,\n FP4_LAYOUT,\n FP8_LAYOUT,\n FP16_LAYOUT,\n FP_LEAF_HEADER_SIZE,\n FPN_LAYOUT,\n type GridTypeLayout,\n HALF_LAYOUT,\n LEAF_FLAG_HAS_BBOX,\n LEAF_OFF_BBOX_DIF_AND_FLAGS,\n LEAF_OFF_BBOX_MIN,\n LEAF_OFF_FP_CODES,\n LEAF_OFF_FP_MINIMUM,\n LEAF_OFF_FP_QUANTUM,\n LEAF_OFF_FP_STAT_AVG,\n LEAF_OFF_FP_STAT_DEV,\n LEAF_OFF_FP_STAT_MAX,\n LEAF_OFF_FP_STAT_MIN,\n LEAF_TABLE_COUNT,\n NODE_FLAG_STATS,\n} from \"./bytes.js\";\nimport type { GridImageWriter } from \"./bytes.js\";\nimport { vdbFloatToHalf, vdbRoundToHalf } from \"./half.js\";\nimport { STATS_FLOAT_MAX, STATS_HALF_MAX, type StatsAccumulator, Vec3StatsAccumulator } from \"./stats.js\";\nimport type { TileValue } from \"./tree.js\";\n\n/** The leaf data a codec needs: origin, all 512 values, mask, active-value stats. */\nexport interface EncodableLeaf {\n origin: [number, number, number];\n values: Float32Array;\n valueMask: Uint32Array;\n stats: StatsAccumulator;\n}\n\n/** Per-leaf encoding plan, computed once by `planLeaf` and reused by `encodeLeaf`. */\nexport interface LeafPlan {\n /** Total byte size of this leaf (header + value table). */\n readonly byteSize: number;\n}\n\n/** Encodes the leaves and constants of one NanoVDB value type (Float, Fp4, Fp8, Fp16, FpN, Vec3f). */\nexport interface VDBLeafCodec {\n /** The grid type's node layout (strides and offsets) that the writer places nodes with. */\n readonly layout: GridTypeLayout;\n /** Scalars per value: 1 (default) or 3 (Vec3f). */\n readonly components?: 1 | 3;\n /**\n * Computes a leaf's encoding plan (its byte size, and for FpN the chosen\n * bit-width) from its 512 values. Called once before layout so variable-size\n * (FpN) leaves can be placed at cumulative offsets.\n *\n * @param values The leaf's 512 values in the leaf's storage order.\n */\n planLeaf(values: Float32Array): LeafPlan;\n /**\n * Writes one leaf's entire block — bbox, `bbox_dif_and_flags`, value mask,\n * value table and per-leaf stats — into the image at absolute byte offset\n * `leafOff`. `plan` is the value returned by {@link planLeaf} for this leaf.\n *\n * @param w The image writer.\n * @param leafOff Absolute byte offset of the leaf in the image.\n * @param leaf The leaf's origin, values, value mask and active-value statistics.\n * @param plan The plan {@link planLeaf} returned for this leaf.\n */\n encodeLeaf(w: GridImageWriter, leafOff: number, leaf: EncodableLeaf, plan: LeafPlan): void;\n /**\n * Writes a single value of the grid's value type: an internal-node tile, the\n * background, or a root/upper/lower min/max statistic of a scalar grid.\n *\n * @param w The image writer.\n * @param off Absolute byte offset to write at.\n * @param value The constant: a number, or `[x, y, z]` for a Vec3f codec.\n */\n writeConstant(w: GridImageWriter, off: number, value: TileValue): void;\n /**\n * Rounds a scalar to what the grid stores (Half: the nearest binary16). When\n * present, `vdbBuildFromLeavesDetailed` passes every leaf value, tile value\n * and the background through it before computing statistics, so min/max/ave\n * describe the stored values (as NanoVDB's GridStats does on a Half grid).\n */\n readonly roundValue?: (value: number) => number;\n}\n\n/** A scalar codec's constant: tiles and backgrounds of scalar grids are numbers. */\nfunction scalar(value: TileValue): number {\n if (typeof value !== \"number\") throw new VDBToolsError(\"VDB_BAD_OPTION\", `leaf codec: expected a scalar value, got [${value.join(\", \")}]`);\n return value;\n}\n\n// ---------------------------------------------------------------------------\n// Shared leaf-header write (bbox + dif/flags + value mask) — common to all codecs\n// ---------------------------------------------------------------------------\n\nfunction clampByte(v: number): number {\n return v < 0 ? 0 : v > 255 ? 255 : v;\n}\n\n/** Writes bbox_min, bbox_dif_and_flags (with `flagsByte` in the high byte) and\n * the 512-bit value mask. Returns nothing; the codec then writes its table. */\nfunction writeLeafHeader(\n w: GridImageWriter,\n leafOff: number,\n leaf: EncodableLeaf,\n flagsByte: number,\n): void {\n const s = leaf.stats;\n const bmin = s.isEmpty ? leaf.origin : s.bboxMin;\n const bmax = s.isEmpty ? leaf.origin : s.bboxMax;\n w.setI32(leafOff + LEAF_OFF_BBOX_MIN, bmin[0]);\n w.setI32(leafOff + LEAF_OFF_BBOX_MIN + 4, bmin[1]);\n w.setI32(leafOff + LEAF_OFF_BBOX_MIN + 8, bmin[2]);\n const difX = clampByte(bmax[0] - bmin[0]);\n const difY = clampByte(bmax[1] - bmin[1]);\n const difZ = clampByte(bmax[2] - bmin[2]);\n w.setU32(\n leafOff + LEAF_OFF_BBOX_DIF_AND_FLAGS,\n (difX | (difY << 8) | (difZ << 16) | (flagsByte << 24)) >>> 0,\n );\n w.setMaskWords(leafOff + 16, leaf.valueMask);\n}\n\n// ---------------------------------------------------------------------------\n// FLOAT\n// ---------------------------------------------------------------------------\n\n/** FLOAT leaf codec: 512 raw f32 values, f32 stats. */\nexport const VDB_FLOAT_LEAF_CODEC: VDBLeafCodec = {\n layout: FLOAT_LAYOUT,\n planLeaf() {\n return { byteSize: FLOAT_LAYOUT.leafSize };\n },\n encodeLeaf(w, leafOff, leaf) {\n writeLeafHeader(w, leafOff, leaf, NODE_FLAG_STATS);\n const L = FLOAT_LAYOUT;\n const values = leaf.values;\n for (let n = 0; n < LEAF_TABLE_COUNT; n++) {\n w.setF32(leafOff + L.leafOffTable + n * 4, values[n]!);\n }\n // Stats block. For an all-inactive leaf the accumulator is empty; write\n // zeros, matching \"no active values\".\n const s = leaf.stats;\n w.setF32(leafOff + L.leafOffMin, s.storedMin(STATS_FLOAT_MAX));\n w.setF32(leafOff + L.leafOffMax, s.storedMax(STATS_FLOAT_MAX));\n w.setF32(leafOff + L.leafOffAve, s.average);\n w.setF32(leafOff + L.leafOffStdDev, s.stdDev);\n },\n writeConstant(w, off, value) {\n w.setF32(off, scalar(value));\n },\n};\n\n// ---------------------------------------------------------------------------\n// Half (K7.H)\n// ---------------------------------------------------------------------------\n\n/**\n * Half leaf codec (`LeafData<Half>`, NanoVDB 13.2): 512 raw IEEE binary16\n * values, binary16 min/max and f32 ave/stddev. Values convert with\n * {@link vdbFloatToHalf} (NanoVDB `math::FloatToHalf`, round to nearest even,\n * overflow to infinity), as `tools::createNanoGrid<FloatGrid, Half>` does.\n * `roundValue` makes the build's statistics describe the stored halves.\n */\nexport const VDB_HALF_LEAF_CODEC: VDBLeafCodec = {\n layout: HALF_LAYOUT,\n roundValue: vdbRoundToHalf,\n planLeaf() {\n return { byteSize: HALF_LAYOUT.leafSize };\n },\n encodeLeaf(w, leafOff, leaf) {\n writeLeafHeader(w, leafOff, leaf, NODE_FLAG_STATS);\n const L = HALF_LAYOUT;\n const values = leaf.values;\n for (let n = 0; n < LEAF_TABLE_COUNT; n++) w.setU16(leafOff + L.leafOffTable + n * 2, vdbFloatToHalf(values[n]!));\n const s = leaf.stats;\n w.setU16(leafOff + L.leafOffMin, vdbFloatToHalf(s.storedMin(STATS_HALF_MAX)));\n w.setU16(leafOff + L.leafOffMax, vdbFloatToHalf(s.storedMax(STATS_HALF_MAX)));\n w.setF32(leafOff + L.leafOffAve, s.average);\n w.setF32(leafOff + L.leafOffStdDev, s.stdDev);\n },\n writeConstant(w, off, value) {\n w.setU16(off, vdbFloatToHalf(scalar(value)));\n },\n};\n\n// ---------------------------------------------------------------------------\n// Vec3f\n// ---------------------------------------------------------------------------\n\n/** Writes a Vec3f (3 x f32) at `off`. */\nfunction writeVec3(w: GridImageWriter, off: number, v: readonly number[]): void {\n w.setF32(off, v[0]!);\n w.setF32(off + 4, v[1]!);\n w.setF32(off + 8, v[2]!);\n}\n\n/**\n * Vec3f leaf codec (K4.2): 512 x 3 f32 values (xyz interleaved in\n * `leaf.values`), Vec3f min/max and f32 ave/stddev of the squared lengths\n * (NanoVDB `Stats<Vec3f, 1>`, see {@link Vec3StatsAccumulator}).\n */\nexport const VDB_VEC3F_LEAF_CODEC: VDBLeafCodec = {\n layout: VEC3F_LAYOUT,\n components: 3,\n planLeaf() {\n return { byteSize: VEC3F_LAYOUT.leafSize };\n },\n encodeLeaf(w, leafOff, leaf) {\n writeLeafHeader(w, leafOff, leaf, NODE_FLAG_STATS);\n const L = VEC3F_LAYOUT;\n const values = leaf.values;\n for (let i = 0; i < LEAF_TABLE_COUNT * 3; i++) w.setF32(leafOff + L.leafOffTable + i * 4, values[i]!);\n writeVec3StatsBlock(w, leafOff, L.leafOffMin, L.leafOffMax, L.leafOffAve, L.leafOffStdDev, leaf.stats);\n },\n writeConstant(w, off, value) {\n if (typeof value === \"number\") throw new VDBToolsError(\"VDB_BAD_OPTION\", `Vec3f codec: expected a vector value, got ${value}`);\n writeVec3(w, off, value);\n },\n};\n\n/** Writes a Vec3f node's stats block: Vec3f min/max (zeros when empty), f32 ave/stddev. */\nexport function writeVec3StatsBlock(\n w: GridImageWriter,\n base: number,\n offMin: number,\n offMax: number,\n offAve: number,\n offStdDev: number,\n stats: StatsAccumulator,\n): void {\n const empty = stats.isEmpty || !(stats instanceof Vec3StatsAccumulator);\n writeVec3(w, base + offMin, empty ? [0, 0, 0] : (stats as Vec3StatsAccumulator).minVec);\n writeVec3(w, base + offMax, empty ? [0, 0, 0] : (stats as Vec3StatsAccumulator).maxVec);\n w.setF32(base + offAve, stats.average);\n w.setF32(base + offStdDev, stats.stdDev);\n}\n\n// ---------------------------------------------------------------------------\n// Quantized (Fp8 / FpN) shared helpers\n// ---------------------------------------------------------------------------\n\nconst fround = Math.fround;\n\n/** Min and max over all 512 leaf values (the affine origin for quantization). */\nfunction leafMinMax(values: Float32Array): { min: number; max: number } {\n let min = Infinity;\n let max = -Infinity;\n for (let n = 0; n < LEAF_TABLE_COUNT; n++) {\n const v = values[n]!;\n if (v < min) min = v;\n if (v > max) max = v;\n }\n return { min, max };\n}\n\n/** `floor(encode*(v-min) + 0.5)` in float32, clamped to `[0, mask]`.\n * Matches native `uint(encode*(v-min) + 0.5f)` with dithering disabled. */\nfunction quantizeF32(v: number, min: number, encode: number, mask: number): number {\n const code = Math.floor(fround(fround(encode * fround(v - min)) + 0.5));\n return code < 0 ? 0 : code > mask ? mask : code;\n}\n\n/** `floor(encode*(v-min) + 0.5)` in double, clamped — the 16-bit FpN path. */\nfunction quantizeF64(v: number, min: number, encode: number, mask: number): number {\n const code = Math.floor(encode * (v - min) + 0.5);\n return code < 0 ? 0 : code > mask ? mask : code;\n}\n\n/** Writes mMinimum, mQuantum (f32) and the four u16 quantized statistics. */\nfunction writeFpHeaderStats(\n w: GridImageWriter,\n leafOff: number,\n min: number,\n quantum: number,\n stats: StatsAccumulator,\n): void {\n w.setF32(leafOff + LEAF_OFF_FP_MINIMUM, min);\n w.setF32(leafOff + LEAF_OFF_FP_QUANTUM, quantum);\n // Quantized active-value statistics (uint16), per LeafFnBase::set{Min,Max,Avg,Dev}.\n const qInv = quantum > 0 ? 1 / quantum : 0;\n const q16 = (x: number): number => {\n const c = Math.floor(x + 0.5);\n return c < 0 ? 0 : c > 0xffff ? 0xffff : c;\n };\n if (stats.isEmpty) {\n w.setU16(leafOff + LEAF_OFF_FP_STAT_MIN, 0);\n w.setU16(leafOff + LEAF_OFF_FP_STAT_MAX, 0);\n w.setU16(leafOff + LEAF_OFF_FP_STAT_AVG, 0);\n w.setU16(leafOff + LEAF_OFF_FP_STAT_DEV, 0);\n return;\n }\n w.setU16(leafOff + LEAF_OFF_FP_STAT_MIN, q16((stats.min - min) * qInv));\n w.setU16(leafOff + LEAF_OFF_FP_STAT_MAX, q16((stats.max - min) * qInv));\n w.setU16(leafOff + LEAF_OFF_FP_STAT_AVG, q16((stats.average - min) * qInv));\n w.setU16(leafOff + LEAF_OFF_FP_STAT_DEV, q16(stats.stdDev * qInv));\n}\n\n/**\n * Packs 512 codes at `bits` bits/value, LSB-first, into the image at\n * `leafOff + 96`. Value `n` occupies global bit range `[n*bits, n*bits+bits)`,\n * exactly what `leafFpReadFloat`'s word/shift addressing reads back.\n */\nfunction packCodes(\n w: GridImageWriter,\n leafOff: number,\n bits: number,\n codeAt: (n: number) => number,\n): void {\n const base = leafOff + LEAF_OFF_FP_CODES;\n const bytes = w.bytes;\n if (bits === 8) {\n for (let n = 0; n < LEAF_TABLE_COUNT; n++) bytes[base + n] = codeAt(n);\n return;\n }\n if (bits === 16) {\n for (let n = 0; n < LEAF_TABLE_COUNT; n++) {\n const c = codeAt(n);\n bytes[base + 2 * n] = c & 0xff;\n bytes[base + 2 * n + 1] = (c >>> 8) & 0xff;\n }\n return;\n }\n // 1/2/4 bits: sub-byte packing (buffer is zero-initialised, so OR in).\n for (let n = 0; n < LEAF_TABLE_COUNT; n++) {\n const c = codeAt(n);\n let g = n * bits;\n for (let b = 0; b < bits; b++) {\n if ((c >>> b) & 1) bytes[base + (g >>> 3)]! |= 1 << (g & 7);\n g++;\n }\n }\n}\n\n// ---------------------------------------------------------------------------\n// Fp4 / Fp8 / Fp16 — fixed bit width\n// ---------------------------------------------------------------------------\n\nfunction makeFixedLeafCodec(layout: GridTypeLayout, bits: 4 | 8 | 16): VDBLeafCodec {\n const mask = (1 << bits) - 1;\n return {\n layout,\n planLeaf() {\n return { byteSize: layout.leafSize };\n },\n encodeLeaf(w, leafOff, leaf) {\n writeLeafHeader(w, leafOff, leaf, LEAF_FLAG_HAS_BBOX);\n const { min, max } = leafMinMax(leaf.values);\n const values = leaf.values;\n if (bits === 16) {\n // Same arithmetic as FpN's 16-bit path: double encode, f32-stored quantum.\n const range = max - min;\n writeFpHeaderStats(w, leafOff, min, range > 0 ? range / mask : 0, leaf.stats);\n const encode = range > 0 ? mask / range : 0;\n packCodes(w, leafOff, 16, (n) => quantizeF64(values[n]!, min, encode, mask));\n return;\n }\n const range = fround(max - min);\n const quantum = range > 0 ? fround(range / mask) : 0;\n writeFpHeaderStats(w, leafOff, min, quantum, leaf.stats);\n const encode = range > 0 ? fround(mask / range) : 0;\n packCodes(w, leafOff, bits, (n) => quantizeF32(values[n]!, min, encode, mask));\n },\n writeConstant(w, off, value) {\n w.setF32(off, scalar(value));\n },\n };\n}\n\n/** Fp4: fixed 4-bit codes (`LeafData<Fp4>`, 16 levels per leaf). */\nexport const VDB_FP4_LEAF_CODEC: VDBLeafCodec = makeFixedLeafCodec(FP4_LAYOUT, 4);\n/** Fp8: fixed 8-bit codes (`LeafData<Fp8>`). */\nexport const VDB_FP8_LEAF_CODEC: VDBLeafCodec = makeFixedLeafCodec(FP8_LAYOUT, 8);\n/** Fp16: fixed 16-bit codes (`LeafData<Fp16>`). */\nexport const VDB_FP16_LEAF_CODEC: VDBLeafCodec = makeFixedLeafCodec(FP16_LAYOUT, 16);\n\n// ---------------------------------------------------------------------------\n// FpN — variable bit-width chosen per leaf by an absolute-difference oracle\n// ---------------------------------------------------------------------------\n\n/** Native's default absolute tolerance for a FogVolume (`AbsDiff::init`). */\nexport const FPN_DEFAULT_TOLERANCE = 0.01;\n\nconst LOG_BITS_MAX = 4; // logBitWidth in [0,4] -> 1,2,4,8,16 bits\n\n/**\n * Picks the smallest logBitWidth (0..4 -> 1,2,4,8,16 bits) whose float32 encode\n * keeps every one of the 512 values within `tolerance` of its dequantized\n * approximation — the exact loop in `CreateNanoGrid::preProcess<FpN>`.\n */\nfunction chooseFpNLogBits(values: Float32Array, min: number, max: number, tolerance: number): number {\n const range = fround(max - min);\n if (!(range > 0)) return 0; // constant leaf -> 1 bit (quantum 0)\n for (let logBits = 0; logBits < LOG_BITS_MAX; logBits++) {\n const mask = (1 << (1 << logBits)) - 1;\n const encode = fround(mask / range);\n const decode = fround(range / mask);\n let ok = true;\n for (let n = 0; n < LEAF_TABLE_COUNT; n++) {\n const exact = values[n]!;\n const code = quantizeF32(exact, min, encode, mask);\n const approx = fround(fround(code * decode) + min);\n if (fround(Math.abs(exact - approx)) > tolerance) {\n ok = false;\n break;\n }\n }\n if (ok) return logBits;\n }\n return LOG_BITS_MAX;\n}\n\ninterface FpNPlan extends LeafPlan {\n readonly logBits: number;\n}\n\n/** Builds an FpN codec for a given absolute tolerance (default: native's 0.01). */\nexport function vdbMakeFpNLeafCodec(tolerance: number = FPN_DEFAULT_TOLERANCE): VDBLeafCodec {\n return {\n layout: FPN_LAYOUT,\n planLeaf(values): FpNPlan {\n const { min, max } = leafMinMax(values);\n const logBits = chooseFpNLogBits(values, min, max, tolerance);\n const bits = 1 << logBits;\n return { byteSize: FP_LEAF_HEADER_SIZE + bits * 64, logBits };\n },\n encodeLeaf(w, leafOff, leaf, plan) {\n const logBits = (plan as FpNPlan).logBits;\n const bits = 1 << logBits;\n writeLeafHeader(w, leafOff, leaf, (logBits << 5) | LEAF_FLAG_HAS_BBOX);\n const { min, max } = leafMinMax(leaf.values);\n const range = max - min;\n const mask = (1 << bits) - 1;\n const quantum = range > 0 ? (bits >= 16 ? range / mask : fround(range / mask)) : 0;\n writeFpHeaderStats(w, leafOff, min, quantum, leaf.stats);\n const values = leaf.values;\n if (bits >= 16) {\n const encode = range > 0 ? 65535 / range : 0;\n packCodes(w, leafOff, bits, (n) => quantizeF64(values[n]!, min, encode, mask));\n } else {\n const encode = range > 0 ? fround(mask / fround(range)) : 0;\n packCodes(w, leafOff, bits, (n) => quantizeF32(values[n]!, min, encode, mask));\n }\n },\n writeConstant(w, off, value) {\n w.setF32(off, scalar(value));\n },\n };\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  /**
2
- * quantize.ts — re-encode a FLOAT NanoVDB grid image as Fp4, Fp8, Fp16 or FpN.
2
+ * quantize.ts — re-encode a Float or Half NanoVDB grid image as Fp4, Fp8, Fp16, FpN, Half or Float.
3
3
  *
4
4
  * Quantization is a leaf-value-representation change only: topology, masks,
5
5
  * internal-node tables/stats, GridData and the transform are unchanged. So
@@ -16,13 +16,28 @@
16
16
  * by decoder round-trip and GPU parity, not byte-compared to `nanovdb_convert`.
17
17
  * - `fpn` — per-leaf variable bit-width, smallest of 1/2/4/8/16 bits whose
18
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`).
19
27
  *
20
- * v1 quantizes FLOAT sources only (throws otherwise) — that is the conversion
21
- * the toolset exposes (`float -> fp8/fpn`), and it is what the native
22
- * `nanovdb_convert --fp8/--fpn` pipeline does too.
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.
23
33
  */
24
34
  import { type VDBBuiltGrid } from "./serialize.js";
25
- export type VDBQuantizeMode = "fp4" | "fp8" | "fp16" | "fpn";
35
+ /**
36
+ * Target encoding of {@link vdbQuantize}: fixed 4, 8 or 16-bit codes, FpN (bit-width chosen per leaf by tolerance),
37
+ * Half (raw IEEE binary16, K7.H) or Float (f32; widens a Half source exactly, K7.H1).
38
+ */
39
+ export type VDBQuantizeMode = "fp4" | "fp8" | "fp16" | "fpn" | "half" | "float";
40
+ /** Options of {@link vdbQuantize}. */
26
41
  export interface VDBQuantizeOptions {
27
42
  /**
28
43
  * Also collapse uniform leaves and nodes of the source into tiles (OpenVDB
@@ -31,13 +46,27 @@ export interface VDBQuantizeOptions {
31
46
  */
32
47
  collapse?: boolean;
33
48
  }
34
- /** Quantizes a FLOAT grid image (or built grid) to Fp8/FpN. Returns a new image. */
49
+ /**
50
+ * Re-encodes a Float or Half grid image (or built grid) as Fp4/Fp8/Fp16/FpN, Half or Float. Returns a new image.
51
+ *
52
+ * @param input A Float or Half grid image, or a built grid.
53
+ * @param mode Target encoding.
54
+ * @param tolerance Absolute error bound for `'fpn'` (leaf bit-width is chosen to meet it); ignored by the other modes.
55
+ * @param options Topology options (leaf collapsing).
56
+ */
35
57
  export declare function vdbQuantize(input: Uint32Array | VDBBuiltGrid, mode: VDBQuantizeMode, tolerance?: number, options?: VDBQuantizeOptions): Uint32Array;
36
- /** As {@link vdbQuantize}, but returns the computed metadata alongside the image. */
58
+ /**
59
+ * As {@link vdbQuantize}, but returns the computed metadata alongside the image.
60
+ *
61
+ * @param input A Float or Half grid image, or a built grid.
62
+ * @param mode Target encoding.
63
+ * @param tolerance Absolute error bound for `'fpn'`; ignored by the fixed-width modes.
64
+ * @param options Topology options (leaf collapsing).
65
+ */
37
66
  export declare function vdbQuantizeDetailed(input: Uint32Array | VDBBuiltGrid, mode: VDBQuantizeMode, tolerance?: number, options?: VDBQuantizeOptions): VDBBuiltGrid;
38
67
  /**
39
- * Re-encodes a FLOAT grid image (still FLOAT) with uniform leaves and nodes
40
- * collapsed into tiles (OpenVDB `prune`, tolerance 0; K4.6). Values read back
41
- * identically; see `tree.ts` for the rules.
68
+ * Re-encodes a Float or Half grid image (same type) with uniform leaves and
69
+ * nodes collapsed into tiles (OpenVDB `prune`, tolerance 0; K4.6; Half since
70
+ * K7.H1). Values read back identically; see `tree.ts` for the rules.
42
71
  */
43
72
  export declare function vdbCollapseGrid(input: Uint32Array | VDBBuiltGrid): VDBBuiltGrid;