@pmndrs/vdb 0.0.0-stage → 0.1.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 (390) hide show
  1. package/CHANGELOG.md +137 -0
  2. package/LICENSE +21 -0
  3. package/README.md +448 -2
  4. package/THIRD_PARTY_NOTICES.md +147 -0
  5. package/dist/core/compute/atlas.d.ts +94 -0
  6. package/dist/core/compute/atlas.js +98 -0
  7. package/dist/core/compute/atlas.js.map +1 -0
  8. package/dist/core/compute/index.d.ts +13 -0
  9. package/dist/core/compute/index.js +9 -0
  10. package/dist/core/compute/index.js.map +1 -0
  11. package/dist/core/compute/pyramid.d.ts +105 -0
  12. package/dist/core/compute/pyramid.js +455 -0
  13. package/dist/core/compute/pyramid.js.map +1 -0
  14. package/dist/core/compute/shared.d.ts +115 -0
  15. package/dist/core/compute/shared.js +211 -0
  16. package/dist/core/compute/shared.js.map +1 -0
  17. package/dist/core/compute/stats.d.ts +71 -0
  18. package/dist/core/compute/stats.js +188 -0
  19. package/dist/core/compute/stats.js.map +1 -0
  20. package/dist/core/compute/value-transform.d.ts +23 -0
  21. package/dist/core/compute/value-transform.js +58 -0
  22. package/dist/core/compute/value-transform.js.map +1 -0
  23. package/dist/core/errors.d.ts +11 -0
  24. package/dist/core/errors.js +9 -0
  25. package/dist/core/errors.js.map +1 -0
  26. package/dist/core/index.d.ts +30 -0
  27. package/dist/core/index.js +27 -0
  28. package/dist/core/index.js.map +1 -0
  29. package/dist/core/internal.d.ts +15 -0
  30. package/dist/core/internal.js +15 -0
  31. package/dist/core/internal.js.map +1 -0
  32. package/dist/core/pool/affine.d.ts +34 -0
  33. package/dist/core/pool/affine.js +100 -0
  34. package/dist/core/pool/affine.js.map +1 -0
  35. package/dist/core/pool/allocator.d.ts +32 -0
  36. package/dist/core/pool/allocator.js +81 -0
  37. package/dist/core/pool/allocator.js.map +1 -0
  38. package/dist/core/pool/image-header.d.ts +82 -0
  39. package/dist/core/pool/image-header.js +175 -0
  40. package/dist/core/pool/image-header.js.map +1 -0
  41. package/dist/core/pool/layout.d.ts +164 -0
  42. package/dist/core/pool/layout.js +267 -0
  43. package/dist/core/pool/layout.js.map +1 -0
  44. package/dist/core/pool/limits.d.ts +40 -0
  45. package/dist/core/pool/limits.js +79 -0
  46. package/dist/core/pool/limits.js.map +1 -0
  47. package/dist/core/pool/pool.d.ts +279 -0
  48. package/dist/core/pool/pool.js +953 -0
  49. package/dist/core/pool/pool.js.map +1 -0
  50. package/dist/core/source/dense.d.ts +19 -0
  51. package/dist/core/source/dense.js +287 -0
  52. package/dist/core/source/dense.js.map +1 -0
  53. package/dist/core/source/types.d.ts +63 -0
  54. package/dist/core/source/types.js +9 -0
  55. package/dist/core/source/types.js.map +1 -0
  56. package/dist/core/types.d.ts +28 -0
  57. package/dist/core/types.js +28 -0
  58. package/dist/core/types.js.map +1 -0
  59. package/dist/core/wgsl/api.d.ts +41 -0
  60. package/dist/core/wgsl/api.js +463 -0
  61. package/dist/core/wgsl/api.js.map +1 -0
  62. package/dist/core/wgsl/generate.d.ts +82 -0
  63. package/dist/core/wgsl/generate.js +505 -0
  64. package/dist/core/wgsl/generate.js.map +1 -0
  65. package/dist/core/wgsl/level-set.d.ts +54 -0
  66. package/dist/core/wgsl/level-set.js +194 -0
  67. package/dist/core/wgsl/level-set.js.map +1 -0
  68. package/dist/core/wgsl/pnanovdb.chunks.generated.d.ts +14 -0
  69. package/dist/core/wgsl/pnanovdb.chunks.generated.js +330 -0
  70. package/dist/core/wgsl/pnanovdb.chunks.generated.js.map +1 -0
  71. package/dist/core/wgsl/reserved.d.ts +9 -0
  72. package/dist/core/wgsl/reserved.js +26 -0
  73. package/dist/core/wgsl/reserved.js.map +1 -0
  74. package/dist/core/wgsl/types.d.ts +104 -0
  75. package/dist/core/wgsl/types.js +2 -0
  76. package/dist/core/wgsl/types.js.map +1 -0
  77. package/dist/three/coarse-first.d.ts +162 -0
  78. package/dist/three/coarse-first.js +187 -0
  79. package/dist/three/coarse-first.js.map +1 -0
  80. package/dist/three/compute.d.ts +63 -0
  81. package/dist/three/compute.js +56 -0
  82. package/dist/three/compute.js.map +1 -0
  83. package/dist/three/device.d.ts +59 -0
  84. package/dist/three/device.js +59 -0
  85. package/dist/three/device.js.map +1 -0
  86. package/dist/three/frame/blackbody.d.ts +42 -0
  87. package/dist/three/frame/blackbody.js +74 -0
  88. package/dist/three/frame/blackbody.js.map +1 -0
  89. package/dist/three/frame/chunks.d.ts +157 -0
  90. package/dist/three/frame/chunks.js +559 -0
  91. package/dist/three/frame/chunks.js.map +1 -0
  92. package/dist/three/frame/density-material.d.ts +53 -0
  93. package/dist/three/frame/density-material.js +353 -0
  94. package/dist/three/frame/density-material.js.map +1 -0
  95. package/dist/three/frame/emission-light.d.ts +167 -0
  96. package/dist/three/frame/emission-light.js +655 -0
  97. package/dist/three/frame/emission-light.js.map +1 -0
  98. package/dist/three/frame/environment-grid-material.d.ts +21 -0
  99. package/dist/three/frame/environment-grid-material.js +184 -0
  100. package/dist/three/frame/environment-grid-material.js.map +1 -0
  101. package/dist/three/frame/environment-material.d.ts +22 -0
  102. package/dist/three/frame/environment-material.js +87 -0
  103. package/dist/three/frame/environment-material.js.map +1 -0
  104. package/dist/three/frame/grid-mip-material.d.ts +12 -0
  105. package/dist/three/frame/grid-mip-material.js +61 -0
  106. package/dist/three/frame/grid-mip-material.js.map +1 -0
  107. package/dist/three/frame/index.d.ts +39 -0
  108. package/dist/three/frame/index.js +35 -0
  109. package/dist/three/frame/index.js.map +1 -0
  110. package/dist/three/frame/inject-material.d.ts +56 -0
  111. package/dist/three/frame/inject-material.js +424 -0
  112. package/dist/three/frame/inject-material.js.map +1 -0
  113. package/dist/three/frame/integrate-material.d.ts +26 -0
  114. package/dist/three/frame/integrate-material.js +198 -0
  115. package/dist/three/frame/integrate-material.js.map +1 -0
  116. package/dist/three/frame/layout.d.ts +34 -0
  117. package/dist/three/frame/layout.js +48 -0
  118. package/dist/three/frame/layout.js.map +1 -0
  119. package/dist/three/frame/lighting-material.d.ts +41 -0
  120. package/dist/three/frame/lighting-material.js +257 -0
  121. package/dist/three/frame/lighting-material.js.map +1 -0
  122. package/dist/three/frame/lights.d.ts +11 -0
  123. package/dist/three/frame/lights.js +16 -0
  124. package/dist/three/frame/lights.js.map +1 -0
  125. package/dist/three/frame/medium.d.ts +21 -0
  126. package/dist/three/frame/medium.js +29 -0
  127. package/dist/three/frame/medium.js.map +1 -0
  128. package/dist/three/frame/neural.d.ts +14 -0
  129. package/dist/three/frame/neural.js +105 -0
  130. package/dist/three/frame/neural.js.map +1 -0
  131. package/dist/three/frame/phase.d.ts +44 -0
  132. package/dist/three/frame/phase.js +80 -0
  133. package/dist/three/frame/phase.js.map +1 -0
  134. package/dist/three/frame/renderer.d.ts +493 -0
  135. package/dist/three/frame/renderer.js +1498 -0
  136. package/dist/three/frame/renderer.js.map +1 -0
  137. package/dist/three/frame/shadow-density-material.d.ts +30 -0
  138. package/dist/three/frame/shadow-density-material.js +123 -0
  139. package/dist/three/frame/shadow-density-material.js.map +1 -0
  140. package/dist/three/frame/spectrum.d.ts +18 -0
  141. package/dist/three/frame/spectrum.js +36 -0
  142. package/dist/three/frame/spectrum.js.map +1 -0
  143. package/dist/three/frame/temporal-material.d.ts +29 -0
  144. package/dist/three/frame/temporal-material.js +152 -0
  145. package/dist/three/frame/temporal-material.js.map +1 -0
  146. package/dist/three/frame/three-internals.d.ts +65 -0
  147. package/dist/three/frame/three-internals.js +150 -0
  148. package/dist/three/frame/three-internals.js.map +1 -0
  149. package/dist/three/frame/transmittance-material.d.ts +31 -0
  150. package/dist/three/frame/transmittance-material.js +315 -0
  151. package/dist/three/frame/transmittance-material.js.map +1 -0
  152. package/dist/three/frame/view.d.ts +103 -0
  153. package/dist/three/frame/view.js +296 -0
  154. package/dist/three/frame/view.js.map +1 -0
  155. package/dist/three/frame/volume-shadow-material.d.ts +36 -0
  156. package/dist/three/frame/volume-shadow-material.js +128 -0
  157. package/dist/three/frame/volume-shadow-material.js.map +1 -0
  158. package/dist/three/frame/volume-shadows.d.ts +153 -0
  159. package/dist/three/frame/volume-shadows.js +756 -0
  160. package/dist/three/frame/volume-shadows.js.map +1 -0
  161. package/dist/three/frame/volume.d.ts +172 -0
  162. package/dist/three/frame/volume.js +256 -0
  163. package/dist/three/frame/volume.js.map +1 -0
  164. package/dist/three/grid-node.d.ts +196 -0
  165. package/dist/three/grid-node.js +510 -0
  166. package/dist/three/grid-node.js.map +1 -0
  167. package/dist/three/index.d.ts +43 -0
  168. package/dist/three/index.js +49 -0
  169. package/dist/three/index.js.map +1 -0
  170. package/dist/three/internal.d.ts +14 -0
  171. package/dist/three/internal.js +14 -0
  172. package/dist/three/internal.js.map +1 -0
  173. package/dist/three/level-set-material.d.ts +112 -0
  174. package/dist/three/level-set-material.js +204 -0
  175. package/dist/three/level-set-material.js.map +1 -0
  176. package/dist/three/material.d.ts +194 -0
  177. package/dist/three/material.js +359 -0
  178. package/dist/three/material.js.map +1 -0
  179. package/dist/three/points.d.ts +84 -0
  180. package/dist/three/points.js +130 -0
  181. package/dist/three/points.js.map +1 -0
  182. package/dist/three/sequence.d.ts +317 -0
  183. package/dist/three/sequence.js +526 -0
  184. package/dist/three/sequence.js.map +1 -0
  185. package/dist/three/sparse-source.d.ts +233 -0
  186. package/dist/three/sparse-source.js +876 -0
  187. package/dist/three/sparse-source.js.map +1 -0
  188. package/dist/three/volume-source.d.ts +167 -0
  189. package/dist/three/volume-source.js +353 -0
  190. package/dist/three/volume-source.js.map +1 -0
  191. package/dist/tools/cpu/compute.d.ts +97 -0
  192. package/dist/tools/cpu/compute.js +218 -0
  193. package/dist/tools/cpu/compute.js.map +1 -0
  194. package/dist/tools/cpu/level-set.d.ts +72 -0
  195. package/dist/tools/cpu/level-set.js +261 -0
  196. package/dist/tools/cpu/level-set.js.map +1 -0
  197. package/dist/tools/cpu/march.d.ts +206 -0
  198. package/dist/tools/cpu/march.js +575 -0
  199. package/dist/tools/cpu/march.js.map +1 -0
  200. package/dist/tools/cpu/probe-coords.d.ts +70 -0
  201. package/dist/tools/cpu/probe-coords.js +116 -0
  202. package/dist/tools/cpu/probe-coords.js.map +1 -0
  203. package/dist/tools/cpu/read-value.d.ts +31 -0
  204. package/dist/tools/cpu/read-value.js +336 -0
  205. package/dist/tools/cpu/read-value.js.map +1 -0
  206. package/dist/tools/cpu/sample-trilinear.d.ts +30 -0
  207. package/dist/tools/cpu/sample-trilinear.js +156 -0
  208. package/dist/tools/cpu/sample-trilinear.js.map +1 -0
  209. package/dist/tools/cpu/stride-tables.d.ts +56 -0
  210. package/dist/tools/cpu/stride-tables.generated.d.ts +1058 -0
  211. package/dist/tools/cpu/stride-tables.generated.js +1266 -0
  212. package/dist/tools/cpu/stride-tables.generated.js.map +1 -0
  213. package/dist/tools/cpu/stride-tables.js +78 -0
  214. package/dist/tools/cpu/stride-tables.js.map +1 -0
  215. package/dist/tools/errors.d.ts +57 -0
  216. package/dist/tools/errors.js +58 -0
  217. package/dist/tools/errors.js.map +1 -0
  218. package/dist/tools/frame/blackbody.d.ts +42 -0
  219. package/dist/tools/frame/blackbody.js +116 -0
  220. package/dist/tools/frame/blackbody.js.map +1 -0
  221. package/dist/tools/frame/emission.d.ts +128 -0
  222. package/dist/tools/frame/emission.js +282 -0
  223. package/dist/tools/frame/emission.js.map +1 -0
  224. package/dist/tools/frame/environment.d.ts +105 -0
  225. package/dist/tools/frame/environment.js +268 -0
  226. package/dist/tools/frame/environment.js.map +1 -0
  227. package/dist/tools/frame/grid.d.ts +302 -0
  228. package/dist/tools/frame/grid.js +703 -0
  229. package/dist/tools/frame/grid.js.map +1 -0
  230. package/dist/tools/frame/index.d.ts +136 -0
  231. package/dist/tools/frame/index.js +348 -0
  232. package/dist/tools/frame/index.js.map +1 -0
  233. package/dist/tools/frame/medium.d.ts +61 -0
  234. package/dist/tools/frame/medium.js +99 -0
  235. package/dist/tools/frame/medium.js.map +1 -0
  236. package/dist/tools/frame/mie-table.d.ts +6 -0
  237. package/dist/tools/frame/mie-table.js +16 -0
  238. package/dist/tools/frame/mie-table.js.map +1 -0
  239. package/dist/tools/frame/mie.d.ts +54 -0
  240. package/dist/tools/frame/mie.js +176 -0
  241. package/dist/tools/frame/mie.js.map +1 -0
  242. package/dist/tools/frame/neural-weights.d.ts +9 -0
  243. package/dist/tools/frame/neural-weights.js +245 -0
  244. package/dist/tools/frame/neural-weights.js.map +1 -0
  245. package/dist/tools/frame/neural.d.ts +80 -0
  246. package/dist/tools/frame/neural.js +150 -0
  247. package/dist/tools/frame/neural.js.map +1 -0
  248. package/dist/tools/frame/pyramid-layout.d.ts +38 -0
  249. package/dist/tools/frame/pyramid-layout.js +53 -0
  250. package/dist/tools/frame/pyramid-layout.js.map +1 -0
  251. package/dist/tools/frame/shadows.d.ts +80 -0
  252. package/dist/tools/frame/shadows.js +182 -0
  253. package/dist/tools/frame/shadows.js.map +1 -0
  254. package/dist/tools/frame/sparse.d.ts +65 -0
  255. package/dist/tools/frame/sparse.js +191 -0
  256. package/dist/tools/frame/sparse.js.map +1 -0
  257. package/dist/tools/frame/spectral.d.ts +203 -0
  258. package/dist/tools/frame/spectral.js +550 -0
  259. package/dist/tools/frame/spectral.js.map +1 -0
  260. package/dist/tools/index.d.ts +106 -0
  261. package/dist/tools/index.js +88 -0
  262. package/dist/tools/index.js.map +1 -0
  263. package/dist/tools/internal.d.ts +46 -0
  264. package/dist/tools/internal.js +31 -0
  265. package/dist/tools/internal.js.map +1 -0
  266. package/dist/tools/nanovdb/build-from-vdb.d.ts +50 -0
  267. package/dist/tools/nanovdb/build-from-vdb.js +92 -0
  268. package/dist/tools/nanovdb/build-from-vdb.js.map +1 -0
  269. package/dist/tools/nanovdb/bytes.d.ts +220 -0
  270. package/dist/tools/nanovdb/bytes.js +345 -0
  271. package/dist/tools/nanovdb/bytes.js.map +1 -0
  272. package/dist/tools/nanovdb/coarse-first.d.ts +62 -0
  273. package/dist/tools/nanovdb/coarse-first.js +86 -0
  274. package/dist/tools/nanovdb/coarse-first.js.map +1 -0
  275. package/dist/tools/nanovdb/index.d.ts +32 -0
  276. package/dist/tools/nanovdb/index.js +24 -0
  277. package/dist/tools/nanovdb/index.js.map +1 -0
  278. package/dist/tools/nanovdb/inspect.d.ts +24 -0
  279. package/dist/tools/nanovdb/inspect.js +63 -0
  280. package/dist/tools/nanovdb/inspect.js.map +1 -0
  281. package/dist/tools/nanovdb/leaf-codec.d.ts +85 -0
  282. package/dist/tools/nanovdb/leaf-codec.js +320 -0
  283. package/dist/tools/nanovdb/leaf-codec.js.map +1 -0
  284. package/dist/tools/nanovdb/quantize.d.ts +43 -0
  285. package/dist/tools/nanovdb/quantize.js +277 -0
  286. package/dist/tools/nanovdb/quantize.js.map +1 -0
  287. package/dist/tools/nanovdb/resample.d.ts +160 -0
  288. package/dist/tools/nanovdb/resample.js +679 -0
  289. package/dist/tools/nanovdb/resample.js.map +1 -0
  290. package/dist/tools/nanovdb/serialize.d.ts +145 -0
  291. package/dist/tools/nanovdb/serialize.js +395 -0
  292. package/dist/tools/nanovdb/serialize.js.map +1 -0
  293. package/dist/tools/nanovdb/stats.d.ts +58 -0
  294. package/dist/tools/nanovdb/stats.js +149 -0
  295. package/dist/tools/nanovdb/stats.js.map +1 -0
  296. package/dist/tools/nanovdb/transform.d.ts +26 -0
  297. package/dist/tools/nanovdb/transform.js +91 -0
  298. package/dist/tools/nanovdb/transform.js.map +1 -0
  299. package/dist/tools/nanovdb/tree.d.ts +175 -0
  300. package/dist/tools/nanovdb/tree.js +518 -0
  301. package/dist/tools/nanovdb/tree.js.map +1 -0
  302. package/dist/tools/nanovdb/write-nvdb.d.ts +39 -0
  303. package/dist/tools/nanovdb/write-nvdb.js +210 -0
  304. package/dist/tools/nanovdb/write-nvdb.js.map +1 -0
  305. package/dist/tools/nvdb-file.d.ts +195 -0
  306. package/dist/tools/nvdb-file.js +606 -0
  307. package/dist/tools/nvdb-file.js.map +1 -0
  308. package/dist/tools/nvdb-stream.d.ts +138 -0
  309. package/dist/tools/nvdb-stream.js +365 -0
  310. package/dist/tools/nvdb-stream.js.map +1 -0
  311. package/dist/tools/vdb/bit-utils.d.ts +20 -0
  312. package/dist/tools/vdb/bit-utils.js +42 -0
  313. package/dist/tools/vdb/bit-utils.js.map +1 -0
  314. package/dist/tools/vdb/blosc.d.ts +56 -0
  315. package/dist/tools/vdb/blosc.js +231 -0
  316. package/dist/tools/vdb/blosc.js.map +1 -0
  317. package/dist/tools/vdb/byte-reader.d.ts +40 -0
  318. package/dist/tools/vdb/byte-reader.js +139 -0
  319. package/dist/tools/vdb/byte-reader.js.map +1 -0
  320. package/dist/tools/vdb/compression.d.ts +73 -0
  321. package/dist/tools/vdb/compression.js +249 -0
  322. package/dist/tools/vdb/compression.js.map +1 -0
  323. package/dist/tools/vdb/errors.d.ts +10 -0
  324. package/dist/tools/vdb/errors.js +11 -0
  325. package/dist/tools/vdb/errors.js.map +1 -0
  326. package/dist/tools/vdb/grid.d.ts +37 -0
  327. package/dist/tools/vdb/grid.js +147 -0
  328. package/dist/tools/vdb/grid.js.map +1 -0
  329. package/dist/tools/vdb/half-float.d.ts +9 -0
  330. package/dist/tools/vdb/half-float.js +24 -0
  331. package/dist/tools/vdb/half-float.js.map +1 -0
  332. package/dist/tools/vdb/index.d.ts +3 -0
  333. package/dist/tools/vdb/index.js +3 -0
  334. package/dist/tools/vdb/index.js.map +1 -0
  335. package/dist/tools/vdb/inflate.d.ts +24 -0
  336. package/dist/tools/vdb/inflate.js +334 -0
  337. package/dist/tools/vdb/inflate.js.map +1 -0
  338. package/dist/tools/vdb/metadata.d.ts +17 -0
  339. package/dist/tools/vdb/metadata.js +72 -0
  340. package/dist/tools/vdb/metadata.js.map +1 -0
  341. package/dist/tools/vdb/parse.d.ts +25 -0
  342. package/dist/tools/vdb/parse.js +171 -0
  343. package/dist/tools/vdb/parse.js.map +1 -0
  344. package/dist/tools/vdb/point-render-data.d.ts +31 -0
  345. package/dist/tools/vdb/point-render-data.js +57 -0
  346. package/dist/tools/vdb/point-render-data.js.map +1 -0
  347. package/dist/tools/vdb/points.d.ts +160 -0
  348. package/dist/tools/vdb/points.js +794 -0
  349. package/dist/tools/vdb/points.js.map +1 -0
  350. package/dist/tools/vdb/transform.d.ts +23 -0
  351. package/dist/tools/vdb/transform.js +54 -0
  352. package/dist/tools/vdb/transform.js.map +1 -0
  353. package/dist/tools/vdb/tree.d.ts +111 -0
  354. package/dist/tools/vdb/tree.js +228 -0
  355. package/dist/tools/vdb/tree.js.map +1 -0
  356. package/dist/tools/vdb/types.d.ts +138 -0
  357. package/dist/tools/vdb/types.js +3 -0
  358. package/dist/tools/vdb/types.js.map +1 -0
  359. package/dist/tools/wvdb/bake.d.ts +116 -0
  360. package/dist/tools/wvdb/bake.js +311 -0
  361. package/dist/tools/wvdb/bake.js.map +1 -0
  362. package/dist/tools/wvdb/dense.d.ts +112 -0
  363. package/dist/tools/wvdb/dense.js +309 -0
  364. package/dist/tools/wvdb/dense.js.map +1 -0
  365. package/dist/tools/wvdb/format.d.ts +161 -0
  366. package/dist/tools/wvdb/format.js +303 -0
  367. package/dist/tools/wvdb/format.js.map +1 -0
  368. package/dist/tools/wvdb/index.d.ts +13 -0
  369. package/dist/tools/wvdb/index.js +14 -0
  370. package/dist/tools/wvdb/index.js.map +1 -0
  371. package/dist/tools/wvdb/level-set.d.ts +48 -0
  372. package/dist/tools/wvdb/level-set.js +153 -0
  373. package/dist/tools/wvdb/level-set.js.map +1 -0
  374. package/dist/tools/wvdb/nanovdb.d.ts +54 -0
  375. package/dist/tools/wvdb/nanovdb.js +60 -0
  376. package/dist/tools/wvdb/nanovdb.js.map +1 -0
  377. package/dist/tools/wvdb/read.d.ts +260 -0
  378. package/dist/tools/wvdb/read.js +743 -0
  379. package/dist/tools/wvdb/read.js.map +1 -0
  380. package/dist/tools/wvdb/sha256.d.ts +7 -0
  381. package/dist/tools/wvdb/sha256.js +76 -0
  382. package/dist/tools/wvdb/sha256.js.map +1 -0
  383. package/dist/tools/wvdb/write.d.ts +127 -0
  384. package/dist/tools/wvdb/write.js +396 -0
  385. package/dist/tools/wvdb/write.js.map +1 -0
  386. package/package.json +82 -4
  387. package/vendor/LICENSE +201 -0
  388. package/vendor/NOTICE +19 -0
  389. package/vendor/VENDOR.md +85 -0
  390. package/vendor/pnanovdb.wgsl +1539 -0
@@ -0,0 +1,24 @@
1
+ /**
2
+ * inspect.ts — a structural report for a NanoVDB grid image: grid type/class,
3
+ * active voxel count, per-level node counts and a memory breakdown by section.
4
+ * Everything is read straight from GridData/TreeData/RootData, so it works on
5
+ * any FLOAT/Fp8/FpN/Vec3f image (ours or native `nanovdb_convert` output).
6
+ *
7
+ * The section sizes use the root/tile/upper/lower strides (shared by FLOAT,
8
+ * Fp8 and FpN; Vec3f has its own); the leaf block is whatever remains up to
9
+ * `mGridSize`, which correctly accounts for FpN's variable-size leaves.
10
+ */
11
+ export interface VDBInspectReport {
12
+ gridType: string;
13
+ gridClass: string;
14
+ voxelCount: number;
15
+ nodeCounts: {
16
+ upper: number;
17
+ lower: number;
18
+ leaf: number;
19
+ };
20
+ /** Byte size of each grid section plus `total` (== mGridSize). */
21
+ memoryBreakdown: Record<string, number>;
22
+ }
23
+ /** Produces a structural + memory report for a NanoVDB grid image. */
24
+ export declare function vdbInspect(image: Uint32Array): VDBInspectReport;
@@ -0,0 +1,63 @@
1
+ /**
2
+ * inspect.ts — a structural report for a NanoVDB grid image: grid type/class,
3
+ * active voxel count, per-level node counts and a memory breakdown by section.
4
+ * Everything is read straight from GridData/TreeData/RootData, so it works on
5
+ * any FLOAT/Fp8/FpN/Vec3f image (ours or native `nanovdb_convert` output).
6
+ *
7
+ * The section sizes use the root/tile/upper/lower strides (shared by FLOAT,
8
+ * Fp8 and FpN; Vec3f has its own); the leaf block is whatever remains up to
9
+ * `mGridSize`, which correctly accounts for FpN's variable-size leaves.
10
+ */
11
+ import { FLOAT_LAYOUT, GRID_TYPE_VEC3F, VEC3F_LAYOUT, GRID_OFF_GRID_CLASS, GRID_OFF_GRID_SIZE, GRID_OFF_GRID_TYPE, GRID_SIZE, ROOT_OFF_TABLE_SIZE, TREE_OFF_NODE_COUNT_LEAF, TREE_OFF_NODE_COUNT_LOWER, TREE_OFF_NODE_COUNT_UPPER, TREE_OFF_NODE_OFFSET_LEAF, TREE_OFF_NODE_OFFSET_ROOT, TREE_OFF_VOXEL_COUNT, TREE_SIZE, } from "./bytes.js";
12
+ const GRID_TYPE_NAMES = {
13
+ 0: "Unknown",
14
+ 1: "Float",
15
+ 2: "Double",
16
+ 6: "Vec3f",
17
+ 14: "Fp8",
18
+ 16: "FpN",
19
+ };
20
+ const GRID_CLASS_NAMES = {
21
+ 0: "Unknown",
22
+ 1: "LevelSet",
23
+ 2: "FogVolume",
24
+ 3: "Staggered",
25
+ };
26
+ /** Produces a structural + memory report for a NanoVDB grid image. */
27
+ export function vdbInspect(image) {
28
+ const view = new DataView(image.buffer, image.byteOffset, image.byteLength);
29
+ const gridTypeId = view.getUint32(GRID_OFF_GRID_TYPE, true);
30
+ const gridClassId = view.getUint32(GRID_OFF_GRID_CLASS, true);
31
+ const total = Number(view.getBigUint64(GRID_OFF_GRID_SIZE, true));
32
+ const treeOff = GRID_SIZE;
33
+ const voxelCount = Number(view.getBigUint64(treeOff + TREE_OFF_VOXEL_COUNT, true));
34
+ const nLeaf = view.getUint32(treeOff + TREE_OFF_NODE_COUNT_LEAF, true);
35
+ const nLower = view.getUint32(treeOff + TREE_OFF_NODE_COUNT_LOWER, true);
36
+ const nUpper = view.getUint32(treeOff + TREE_OFF_NODE_COUNT_UPPER, true);
37
+ const rootOff = treeOff + Number(view.getBigUint64(treeOff + TREE_OFF_NODE_OFFSET_ROOT, true));
38
+ const nTiles = view.getUint32(rootOff + ROOT_OFF_TABLE_SIZE, true);
39
+ const leafOff = treeOff + Number(view.getBigUint64(treeOff + TREE_OFF_NODE_OFFSET_LEAF, true));
40
+ // Root/tile/upper/lower strides are shared by FLOAT/Fp8/FpN; Vec3f differs.
41
+ const L = gridTypeId === GRID_TYPE_VEC3F ? VEC3F_LAYOUT : FLOAT_LAYOUT;
42
+ const rootSection = L.rootSize + nTiles * L.rootTileSize;
43
+ const upperSection = nUpper * L.upperSize;
44
+ const lowerSection = nLower * L.lowerSize;
45
+ // Leaf block is the remainder to end-of-grid — correct even for variable-size FpN leaves.
46
+ const leafSection = Math.max(0, total - leafOff);
47
+ return {
48
+ gridType: GRID_TYPE_NAMES[gridTypeId] ?? `type#${gridTypeId}`,
49
+ gridClass: GRID_CLASS_NAMES[gridClassId] ?? `class#${gridClassId}`,
50
+ voxelCount,
51
+ nodeCounts: { upper: nUpper, lower: nLower, leaf: nLeaf },
52
+ memoryBreakdown: {
53
+ gridData: GRID_SIZE,
54
+ tree: TREE_SIZE,
55
+ root: rootSection,
56
+ upper: upperSection,
57
+ lower: lowerSection,
58
+ leaf: leafSection,
59
+ total,
60
+ },
61
+ };
62
+ }
63
+ //# sourceMappingURL=inspect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inspect.js","sourceRoot":"","sources":["../../../src/tools/nanovdb/inspect.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EACL,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EAClB,SAAS,EACT,mBAAmB,EACnB,wBAAwB,EACxB,yBAAyB,EACzB,yBAAyB,EACzB,yBAAyB,EACzB,yBAAyB,EACzB,oBAAoB,EACpB,SAAS,GACV,MAAM,YAAY,CAAC;AAWpB,MAAM,eAAe,GAA2B;IAC9C,CAAC,EAAE,SAAS;IACZ,CAAC,EAAE,OAAO;IACV,CAAC,EAAE,QAAQ;IACX,CAAC,EAAE,OAAO;IACV,EAAE,EAAE,KAAK;IACT,EAAE,EAAE,KAAK;CACV,CAAC;AAEF,MAAM,gBAAgB,GAA2B;IAC/C,CAAC,EAAE,SAAS;IACZ,CAAC,EAAE,UAAU;IACb,CAAC,EAAE,WAAW;IACd,CAAC,EAAE,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A4E;IAC5E,MAAM,CAAC,GAAG,UAAU,KAAK,eAAe,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC;IACvE,MAAM,WAAW,GAAG,CAAC,CAAC,QAAQ,GAAG,MAAM,GAAG,CAAC,CAAC,YAAY,CAAC;IACzD,MAAM,YAAY,GAAG,MAAM,GAAG,CAAC,CAAC,SAAS,CAAC;IAC1C,MAAM,YAAY,GAAG,MAAM,GAAG,CAAC,CAAC,SAAS,CAAC;IAC1C,0FAA0F;IAC1F,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC,CAAC;IAEjD,OAAO;QACL,QAAQ,EAAE,eAAe,CAAC,UAAU,CAAC,IAAI,QAAQ,UAAU,EAAE;QAC7D,SAAS,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\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,\n total,\n },\n };\n}\n"]}
@@ -0,0 +1,85 @@
1
+ /**
2
+ * leaf-codec.ts — the leaf value-table encoder abstraction.
3
+ *
4
+ * The leaf is the only block whose *value representation* varies by grid type:
5
+ * FLOAT stores 512 plain f32s; Fp8/FpN store a per-leaf (min, quantum) pair plus
6
+ * a packed bit-stream of quantized codes. Everything else about a grid image
7
+ * (topology, masks, internal-node tables, stats, bbox, GridData) is identical
8
+ * across those types — the internal-node/root tiles and background stay plain
9
+ * f32 even for quantized grids (verified against native fp8/fpn fixtures). So the
10
+ * serializer is parameterised over a {@link VDBLeafCodec}: `serialize.ts` lays out
11
+ * the common blocks and hands each leaf to the codec, which owns the full leaf
12
+ * write (bbox, flags, value mask, value table and per-leaf stats).
13
+ *
14
+ * Three codecs ship:
15
+ * - {@link VDB_FLOAT_LEAF_CODEC} — 512 raw f32 values + f32 stats.
16
+ * - {@link VDB_FP4_LEAF_CODEC} / {@link VDB_FP8_LEAF_CODEC} / {@link VDB_FP16_LEAF_CODEC} — fixed 4/8/16-bit
17
+ * quantization (`LeafData<Fp4|Fp8|Fp16>`).
18
+ * - {@link vdbMakeFpNLeafCodec} — variable bit-width (`LeafData<FpN>`); a
19
+ * per-leaf oracle picks the smallest of 1/2/4/8/16 bits meeting a tolerance.
20
+ *
21
+ * ## Encode authority
22
+ *
23
+ * The quantization mirrors `nanovdb::tools::CreateNanoGrid` (NanoVDB.h
24
+ * `LeafFnBase`/`LeafData<Fp8|FpN>` + CreateNanoGrid.h `processLeafs`) and must
25
+ * satisfy the repo's proven decoders (`read-value.ts` `leafFp*ReadFloat` and
26
+ * `pnanovdb.wgsl`). Per-leaf `mMinimum`/`mQuantum` = min / (max-min)/((1<<bits)-1)
27
+ * over ALL 512 values (active and inactive). A code is
28
+ * `floor(encode*(v-min) + 0.5)` — round-to-nearest, matching native's
29
+ * dithering-off `DitherLUT` (constant 0.5). Codes are packed LSB-first, value `n`
30
+ * at global bit `n*bits`, identical to the reader's word/shift addressing.
31
+ */
32
+ import { type GridTypeLayout } from "./bytes.js";
33
+ import type { GridImageWriter } from "./bytes.js";
34
+ import { type StatsAccumulator } from "./stats.js";
35
+ import type { TileValue } from "./tree.js";
36
+ /** The leaf data a codec needs: origin, all 512 values, mask, active-value stats. */
37
+ export interface EncodableLeaf {
38
+ origin: [number, number, number];
39
+ values: Float32Array;
40
+ valueMask: Uint32Array;
41
+ stats: StatsAccumulator;
42
+ }
43
+ /** Per-leaf encoding plan, computed once by `planLeaf` and reused by `encodeLeaf`. */
44
+ export interface LeafPlan {
45
+ /** Total byte size of this leaf (header + value table). */
46
+ readonly byteSize: number;
47
+ }
48
+ export interface VDBLeafCodec {
49
+ readonly layout: GridTypeLayout;
50
+ /** Scalars per value: 1 (default) or 3 (Vec3f). */
51
+ readonly components?: 1 | 3;
52
+ /**
53
+ * Computes a leaf's encoding plan (its byte size, and for FpN the chosen
54
+ * bit-width) from its 512 values. Called once before layout so variable-size
55
+ * (FpN) leaves can be placed at cumulative offsets.
56
+ */
57
+ planLeaf(values: Float32Array): LeafPlan;
58
+ /**
59
+ * Writes one leaf's entire block — bbox, `bbox_dif_and_flags`, value mask,
60
+ * value table and per-leaf stats — into the image at absolute byte offset
61
+ * `leafOff`. `plan` is the value returned by {@link planLeaf} for this leaf.
62
+ */
63
+ encodeLeaf(w: GridImageWriter, leafOff: number, leaf: EncodableLeaf, plan: LeafPlan): void;
64
+ /** Writes a single constant value (an internal-node tile / background). */
65
+ writeConstant(w: GridImageWriter, off: number, value: TileValue): void;
66
+ }
67
+ /** FLOAT leaf codec: 512 raw f32 values, f32 stats. */
68
+ export declare const VDB_FLOAT_LEAF_CODEC: VDBLeafCodec;
69
+ /**
70
+ * Vec3f leaf codec (K4.2): 512 x 3 f32 values (xyz interleaved in
71
+ * `leaf.values`), Vec3f min/max and f32 ave/stddev of the squared lengths
72
+ * (NanoVDB `Stats<Vec3f, 1>`, see {@link Vec3StatsAccumulator}).
73
+ */
74
+ export declare const VDB_VEC3F_LEAF_CODEC: VDBLeafCodec;
75
+ /** Writes a Vec3f node's stats block: Vec3f min/max (zeros when empty), f32 ave/stddev. */
76
+ export declare function writeVec3StatsBlock(w: GridImageWriter, base: number, offMin: number, offMax: number, offAve: number, offStdDev: number, stats: StatsAccumulator): void;
77
+ /** Fp4: fixed 4-bit codes (`LeafData<Fp4>`, 16 levels per leaf). */
78
+ export declare const VDB_FP4_LEAF_CODEC: VDBLeafCodec;
79
+ export declare const VDB_FP8_LEAF_CODEC: VDBLeafCodec;
80
+ /** Fp16: fixed 16-bit codes (`LeafData<Fp16>`). */
81
+ export declare const VDB_FP16_LEAF_CODEC: VDBLeafCodec;
82
+ /** Native's default absolute tolerance for a FogVolume (`AbsDiff::init`). */
83
+ export declare const FPN_DEFAULT_TOLERANCE = 0.01;
84
+ /** Builds an FpN codec for a given absolute tolerance (default: native's 0.01). */
85
+ export declare function vdbMakeFpNLeafCodec(tolerance?: number): VDBLeafCodec;
@@ -0,0 +1,320 @@
1
+ /**
2
+ * leaf-codec.ts — the leaf value-table encoder abstraction.
3
+ *
4
+ * The leaf is the only block whose *value representation* varies by grid type:
5
+ * FLOAT stores 512 plain f32s; Fp8/FpN store a per-leaf (min, quantum) pair plus
6
+ * a packed bit-stream of quantized codes. Everything else about a grid image
7
+ * (topology, masks, internal-node tables, stats, bbox, GridData) is identical
8
+ * across those types — the internal-node/root tiles and background stay plain
9
+ * f32 even for quantized grids (verified against native fp8/fpn fixtures). So the
10
+ * serializer is parameterised over a {@link VDBLeafCodec}: `serialize.ts` lays out
11
+ * the common blocks and hands each leaf to the codec, which owns the full leaf
12
+ * write (bbox, flags, value mask, value table and per-leaf stats).
13
+ *
14
+ * Three codecs ship:
15
+ * - {@link VDB_FLOAT_LEAF_CODEC} — 512 raw f32 values + f32 stats.
16
+ * - {@link VDB_FP4_LEAF_CODEC} / {@link VDB_FP8_LEAF_CODEC} / {@link VDB_FP16_LEAF_CODEC} — fixed 4/8/16-bit
17
+ * quantization (`LeafData<Fp4|Fp8|Fp16>`).
18
+ * - {@link vdbMakeFpNLeafCodec} — variable bit-width (`LeafData<FpN>`); a
19
+ * per-leaf oracle picks the smallest of 1/2/4/8/16 bits meeting a tolerance.
20
+ *
21
+ * ## Encode authority
22
+ *
23
+ * The quantization mirrors `nanovdb::tools::CreateNanoGrid` (NanoVDB.h
24
+ * `LeafFnBase`/`LeafData<Fp8|FpN>` + CreateNanoGrid.h `processLeafs`) and must
25
+ * satisfy the repo's proven decoders (`read-value.ts` `leafFp*ReadFloat` and
26
+ * `pnanovdb.wgsl`). Per-leaf `mMinimum`/`mQuantum` = min / (max-min)/((1<<bits)-1)
27
+ * over ALL 512 values (active and inactive). A code is
28
+ * `floor(encode*(v-min) + 0.5)` — round-to-nearest, matching native's
29
+ * dithering-off `DitherLUT` (constant 0.5). Codes are packed LSB-first, value `n`
30
+ * at global bit `n*bits`, identical to the reader's word/shift addressing.
31
+ */
32
+ 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
+ /** A scalar codec's constant: tiles and backgrounds of scalar grids are numbers. */
36
+ function scalar(value) {
37
+ if (typeof value !== "number")
38
+ throw new VDBToolsError("VDB_BAD_OPTION", `leaf codec: expected a scalar value, got [${value.join(", ")}]`);
39
+ return value;
40
+ }
41
+ // ---------------------------------------------------------------------------
42
+ // Shared leaf-header write (bbox + dif/flags + value mask) — common to all codecs
43
+ // ---------------------------------------------------------------------------
44
+ function clampByte(v) {
45
+ return v < 0 ? 0 : v > 255 ? 255 : v;
46
+ }
47
+ /** Writes bbox_min, bbox_dif_and_flags (with `flagsByte` in the high byte) and
48
+ * the 512-bit value mask. Returns nothing; the codec then writes its table. */
49
+ function writeLeafHeader(w, leafOff, leaf, flagsByte) {
50
+ const s = leaf.stats;
51
+ const bmin = s.isEmpty ? leaf.origin : s.bboxMin;
52
+ const bmax = s.isEmpty ? leaf.origin : s.bboxMax;
53
+ w.setI32(leafOff + LEAF_OFF_BBOX_MIN, bmin[0]);
54
+ w.setI32(leafOff + LEAF_OFF_BBOX_MIN + 4, bmin[1]);
55
+ w.setI32(leafOff + LEAF_OFF_BBOX_MIN + 8, bmin[2]);
56
+ const difX = clampByte(bmax[0] - bmin[0]);
57
+ const difY = clampByte(bmax[1] - bmin[1]);
58
+ const difZ = clampByte(bmax[2] - bmin[2]);
59
+ w.setU32(leafOff + LEAF_OFF_BBOX_DIF_AND_FLAGS, (difX | (difY << 8) | (difZ << 16) | (flagsByte << 24)) >>> 0);
60
+ w.setMaskWords(leafOff + 16, leaf.valueMask);
61
+ }
62
+ // ---------------------------------------------------------------------------
63
+ // FLOAT
64
+ // ---------------------------------------------------------------------------
65
+ /** FLOAT leaf codec: 512 raw f32 values, f32 stats. */
66
+ export const VDB_FLOAT_LEAF_CODEC = {
67
+ layout: FLOAT_LAYOUT,
68
+ planLeaf() {
69
+ return { byteSize: FLOAT_LAYOUT.leafSize };
70
+ },
71
+ encodeLeaf(w, leafOff, leaf) {
72
+ writeLeafHeader(w, leafOff, leaf, NODE_FLAG_STATS);
73
+ const L = FLOAT_LAYOUT;
74
+ const values = leaf.values;
75
+ for (let n = 0; n < LEAF_TABLE_COUNT; n++) {
76
+ w.setF32(leafOff + L.leafOffTable + n * 4, values[n]);
77
+ }
78
+ // Stats block. For an all-inactive leaf the accumulator is empty; write
79
+ // zeros, matching "no active values".
80
+ 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);
83
+ w.setF32(leafOff + L.leafOffAve, s.average);
84
+ w.setF32(leafOff + L.leafOffStdDev, s.stdDev);
85
+ },
86
+ writeConstant(w, off, value) {
87
+ w.setF32(off, scalar(value));
88
+ },
89
+ };
90
+ // ---------------------------------------------------------------------------
91
+ // Vec3f
92
+ // ---------------------------------------------------------------------------
93
+ /** Writes a Vec3f (3 x f32) at `off`. */
94
+ function writeVec3(w, off, v) {
95
+ w.setF32(off, v[0]);
96
+ w.setF32(off + 4, v[1]);
97
+ w.setF32(off + 8, v[2]);
98
+ }
99
+ /**
100
+ * Vec3f leaf codec (K4.2): 512 x 3 f32 values (xyz interleaved in
101
+ * `leaf.values`), Vec3f min/max and f32 ave/stddev of the squared lengths
102
+ * (NanoVDB `Stats<Vec3f, 1>`, see {@link Vec3StatsAccumulator}).
103
+ */
104
+ export const VDB_VEC3F_LEAF_CODEC = {
105
+ layout: VEC3F_LAYOUT,
106
+ components: 3,
107
+ planLeaf() {
108
+ return { byteSize: VEC3F_LAYOUT.leafSize };
109
+ },
110
+ encodeLeaf(w, leafOff, leaf) {
111
+ writeLeafHeader(w, leafOff, leaf, NODE_FLAG_STATS);
112
+ const L = VEC3F_LAYOUT;
113
+ const values = leaf.values;
114
+ for (let i = 0; i < LEAF_TABLE_COUNT * 3; i++)
115
+ w.setF32(leafOff + L.leafOffTable + i * 4, values[i]);
116
+ writeVec3StatsBlock(w, leafOff, L.leafOffMin, L.leafOffMax, L.leafOffAve, L.leafOffStdDev, leaf.stats);
117
+ },
118
+ writeConstant(w, off, value) {
119
+ if (typeof value === "number")
120
+ throw new VDBToolsError("VDB_BAD_OPTION", `Vec3f codec: expected a vector value, got ${value}`);
121
+ writeVec3(w, off, value);
122
+ },
123
+ };
124
+ /** Writes a Vec3f node's stats block: Vec3f min/max (zeros when empty), f32 ave/stddev. */
125
+ export function writeVec3StatsBlock(w, base, offMin, offMax, offAve, offStdDev, stats) {
126
+ const empty = stats.isEmpty || !(stats instanceof Vec3StatsAccumulator);
127
+ writeVec3(w, base + offMin, empty ? [0, 0, 0] : stats.minVec);
128
+ writeVec3(w, base + offMax, empty ? [0, 0, 0] : stats.maxVec);
129
+ w.setF32(base + offAve, stats.average);
130
+ w.setF32(base + offStdDev, stats.stdDev);
131
+ }
132
+ // ---------------------------------------------------------------------------
133
+ // Quantized (Fp8 / FpN) shared helpers
134
+ // ---------------------------------------------------------------------------
135
+ const fround = Math.fround;
136
+ /** Min and max over all 512 leaf values (the affine origin for quantization). */
137
+ function leafMinMax(values) {
138
+ let min = Infinity;
139
+ let max = -Infinity;
140
+ for (let n = 0; n < LEAF_TABLE_COUNT; n++) {
141
+ const v = values[n];
142
+ if (v < min)
143
+ min = v;
144
+ if (v > max)
145
+ max = v;
146
+ }
147
+ return { min, max };
148
+ }
149
+ /** `floor(encode*(v-min) + 0.5)` in float32, clamped to `[0, mask]`.
150
+ * Matches native `uint(encode*(v-min) + 0.5f)` with dithering disabled. */
151
+ function quantizeF32(v, min, encode, mask) {
152
+ const code = Math.floor(fround(fround(encode * fround(v - min)) + 0.5));
153
+ return code < 0 ? 0 : code > mask ? mask : code;
154
+ }
155
+ /** `floor(encode*(v-min) + 0.5)` in double, clamped — the 16-bit FpN path. */
156
+ function quantizeF64(v, min, encode, mask) {
157
+ const code = Math.floor(encode * (v - min) + 0.5);
158
+ return code < 0 ? 0 : code > mask ? mask : code;
159
+ }
160
+ /** Writes mMinimum, mQuantum (f32) and the four u16 quantized statistics. */
161
+ function writeFpHeaderStats(w, leafOff, min, quantum, stats) {
162
+ w.setF32(leafOff + LEAF_OFF_FP_MINIMUM, min);
163
+ w.setF32(leafOff + LEAF_OFF_FP_QUANTUM, quantum);
164
+ // Quantized active-value statistics (uint16), per LeafFnBase::set{Min,Max,Avg,Dev}.
165
+ const qInv = quantum > 0 ? 1 / quantum : 0;
166
+ const q16 = (x) => {
167
+ const c = Math.floor(x + 0.5);
168
+ return c < 0 ? 0 : c > 0xffff ? 0xffff : c;
169
+ };
170
+ if (stats.isEmpty) {
171
+ w.setU16(leafOff + LEAF_OFF_FP_STAT_MIN, 0);
172
+ w.setU16(leafOff + LEAF_OFF_FP_STAT_MAX, 0);
173
+ w.setU16(leafOff + LEAF_OFF_FP_STAT_AVG, 0);
174
+ w.setU16(leafOff + LEAF_OFF_FP_STAT_DEV, 0);
175
+ return;
176
+ }
177
+ w.setU16(leafOff + LEAF_OFF_FP_STAT_MIN, q16((stats.min - min) * qInv));
178
+ w.setU16(leafOff + LEAF_OFF_FP_STAT_MAX, q16((stats.max - min) * qInv));
179
+ w.setU16(leafOff + LEAF_OFF_FP_STAT_AVG, q16((stats.average - min) * qInv));
180
+ w.setU16(leafOff + LEAF_OFF_FP_STAT_DEV, q16(stats.stdDev * qInv));
181
+ }
182
+ /**
183
+ * Packs 512 codes at `bits` bits/value, LSB-first, into the image at
184
+ * `leafOff + 96`. Value `n` occupies global bit range `[n*bits, n*bits+bits)`,
185
+ * exactly what `leafFpReadFloat`'s word/shift addressing reads back.
186
+ */
187
+ function packCodes(w, leafOff, bits, codeAt) {
188
+ const base = leafOff + LEAF_OFF_FP_CODES;
189
+ const bytes = w.bytes;
190
+ if (bits === 8) {
191
+ for (let n = 0; n < LEAF_TABLE_COUNT; n++)
192
+ bytes[base + n] = codeAt(n);
193
+ return;
194
+ }
195
+ if (bits === 16) {
196
+ for (let n = 0; n < LEAF_TABLE_COUNT; n++) {
197
+ const c = codeAt(n);
198
+ bytes[base + 2 * n] = c & 0xff;
199
+ bytes[base + 2 * n + 1] = (c >>> 8) & 0xff;
200
+ }
201
+ return;
202
+ }
203
+ // 1/2/4 bits: sub-byte packing (buffer is zero-initialised, so OR in).
204
+ for (let n = 0; n < LEAF_TABLE_COUNT; n++) {
205
+ const c = codeAt(n);
206
+ let g = n * bits;
207
+ for (let b = 0; b < bits; b++) {
208
+ if ((c >>> b) & 1)
209
+ bytes[base + (g >>> 3)] |= 1 << (g & 7);
210
+ g++;
211
+ }
212
+ }
213
+ }
214
+ // ---------------------------------------------------------------------------
215
+ // Fp4 / Fp8 / Fp16 — fixed bit width
216
+ // ---------------------------------------------------------------------------
217
+ function makeFixedLeafCodec(layout, bits) {
218
+ const mask = (1 << bits) - 1;
219
+ return {
220
+ layout,
221
+ planLeaf() {
222
+ return { byteSize: layout.leafSize };
223
+ },
224
+ encodeLeaf(w, leafOff, leaf) {
225
+ writeLeafHeader(w, leafOff, leaf, LEAF_FLAG_HAS_BBOX);
226
+ const { min, max } = leafMinMax(leaf.values);
227
+ const values = leaf.values;
228
+ if (bits === 16) {
229
+ // Same arithmetic as FpN's 16-bit path: double encode, f32-stored quantum.
230
+ const range = max - min;
231
+ writeFpHeaderStats(w, leafOff, min, range > 0 ? range / mask : 0, leaf.stats);
232
+ const encode = range > 0 ? mask / range : 0;
233
+ packCodes(w, leafOff, 16, (n) => quantizeF64(values[n], min, encode, mask));
234
+ return;
235
+ }
236
+ const range = fround(max - min);
237
+ const quantum = range > 0 ? fround(range / mask) : 0;
238
+ writeFpHeaderStats(w, leafOff, min, quantum, leaf.stats);
239
+ const encode = range > 0 ? fround(mask / range) : 0;
240
+ packCodes(w, leafOff, bits, (n) => quantizeF32(values[n], min, encode, mask));
241
+ },
242
+ writeConstant(w, off, value) {
243
+ w.setF32(off, scalar(value));
244
+ },
245
+ };
246
+ }
247
+ /** Fp4: fixed 4-bit codes (`LeafData<Fp4>`, 16 levels per leaf). */
248
+ export const VDB_FP4_LEAF_CODEC = makeFixedLeafCodec(FP4_LAYOUT, 4);
249
+ export const VDB_FP8_LEAF_CODEC = makeFixedLeafCodec(FP8_LAYOUT, 8);
250
+ /** Fp16: fixed 16-bit codes (`LeafData<Fp16>`). */
251
+ export const VDB_FP16_LEAF_CODEC = makeFixedLeafCodec(FP16_LAYOUT, 16);
252
+ // ---------------------------------------------------------------------------
253
+ // FpN — variable bit-width chosen per leaf by an absolute-difference oracle
254
+ // ---------------------------------------------------------------------------
255
+ /** Native's default absolute tolerance for a FogVolume (`AbsDiff::init`). */
256
+ export const FPN_DEFAULT_TOLERANCE = 0.01;
257
+ const LOG_BITS_MAX = 4; // logBitWidth in [0,4] -> 1,2,4,8,16 bits
258
+ /**
259
+ * Picks the smallest logBitWidth (0..4 -> 1,2,4,8,16 bits) whose float32 encode
260
+ * keeps every one of the 512 values within `tolerance` of its dequantized
261
+ * approximation — the exact loop in `CreateNanoGrid::preProcess<FpN>`.
262
+ */
263
+ function chooseFpNLogBits(values, min, max, tolerance) {
264
+ const range = fround(max - min);
265
+ if (!(range > 0))
266
+ return 0; // constant leaf -> 1 bit (quantum 0)
267
+ for (let logBits = 0; logBits < LOG_BITS_MAX; logBits++) {
268
+ const mask = (1 << (1 << logBits)) - 1;
269
+ const encode = fround(mask / range);
270
+ const decode = fround(range / mask);
271
+ let ok = true;
272
+ for (let n = 0; n < LEAF_TABLE_COUNT; n++) {
273
+ const exact = values[n];
274
+ const code = quantizeF32(exact, min, encode, mask);
275
+ const approx = fround(fround(code * decode) + min);
276
+ if (fround(Math.abs(exact - approx)) > tolerance) {
277
+ ok = false;
278
+ break;
279
+ }
280
+ }
281
+ if (ok)
282
+ return logBits;
283
+ }
284
+ return LOG_BITS_MAX;
285
+ }
286
+ /** Builds an FpN codec for a given absolute tolerance (default: native's 0.01). */
287
+ export function vdbMakeFpNLeafCodec(tolerance = FPN_DEFAULT_TOLERANCE) {
288
+ return {
289
+ layout: FPN_LAYOUT,
290
+ planLeaf(values) {
291
+ const { min, max } = leafMinMax(values);
292
+ const logBits = chooseFpNLogBits(values, min, max, tolerance);
293
+ const bits = 1 << logBits;
294
+ return { byteSize: FP_LEAF_HEADER_SIZE + bits * 64, logBits };
295
+ },
296
+ encodeLeaf(w, leafOff, leaf, plan) {
297
+ const logBits = plan.logBits;
298
+ const bits = 1 << logBits;
299
+ writeLeafHeader(w, leafOff, leaf, (logBits << 5) | LEAF_FLAG_HAS_BBOX);
300
+ const { min, max } = leafMinMax(leaf.values);
301
+ const range = max - min;
302
+ const mask = (1 << bits) - 1;
303
+ const quantum = range > 0 ? (bits >= 16 ? range / mask : fround(range / mask)) : 0;
304
+ writeFpHeaderStats(w, leafOff, min, quantum, leaf.stats);
305
+ const values = leaf.values;
306
+ if (bits >= 16) {
307
+ const encode = range > 0 ? 65535 / range : 0;
308
+ packCodes(w, leafOff, bits, (n) => quantizeF64(values[n], min, encode, mask));
309
+ }
310
+ else {
311
+ const encode = range > 0 ? fround(mask / fround(range)) : 0;
312
+ packCodes(w, leafOff, bits, (n) => quantizeF32(values[n], min, encode, mask));
313
+ }
314
+ },
315
+ writeConstant(w, off, value) {
316
+ w.setF32(off, scalar(value));
317
+ },
318
+ };
319
+ }
320
+ //# sourceMappingURL=leaf-codec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"leaf-codec.js","sourceRoot":"","sources":["../../../src/tools/n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YACzD,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;YAC3B,IAAI,IAAI,IAAI,EAAE,EAAE,CAAC;gBACf,MAAM,MAAM,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC7C,SAAS,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAE,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;YACjF,CAAC;iBAAM,CAAC;gBACN,MAAM,MAAM,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC5D,SAAS,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAE,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;YACjF,CAAC;QACH,CAAC;QACD,aAAa,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK;YACzB,CAAC,CAAC,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 *\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"]}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * quantize.ts — re-encode a FLOAT NanoVDB grid image as Fp4, Fp8, Fp16 or FpN.
3
+ *
4
+ * Quantization is a leaf-value-representation change only: topology, masks,
5
+ * internal-node tables/stats, GridData and the transform are unchanged. So
6
+ * `quantize` reads the source FLOAT image's leaves (each: 8-aligned origin,
7
+ * all 512 values, value mask), its active tiles (root, upper, lower; kept as
8
+ * tiles since K4.1 — tile values stay plain f32 in Fp8/FpN grids) and its
9
+ * GridData transform/background, then re-runs the leaf-iterator build path
10
+ * ({@link vdbBuildFromLeavesDetailed}) with the chosen quantizing {@link VDBLeafCodec}. The result satisfies the repo's proven decoders
11
+ * (`read-value.ts` `leafFp*ReadFloat`, `pnanovdb.wgsl`).
12
+ *
13
+ * - `fp4` / `fp8` / `fp16` — fixed 4/8/16-bit codes; per-leaf quantum = (max-min)/(2^bits-1).
14
+ * The CreateNanoGrid rules Fp8 uses (min/quantum over all 512 values, round-to-nearest, no
15
+ * dither); `tolerance` is ignored. No native Fp4/Fp16 fixtures exist, so these are verified
16
+ * by decoder round-trip and GPU parity, not byte-compared to `nanovdb_convert`.
17
+ * - `fpn` — per-leaf variable bit-width, smallest of 1/2/4/8/16 bits whose
18
+ * dequantized values stay within `tolerance` (default: native's FogVolume 0.01).
19
+ *
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.
23
+ */
24
+ import { type VDBBuiltGrid } from "./serialize.js";
25
+ export type VDBQuantizeMode = "fp4" | "fp8" | "fp16" | "fpn";
26
+ export interface VDBQuantizeOptions {
27
+ /**
28
+ * Also collapse uniform leaves and nodes of the source into tiles (OpenVDB
29
+ * `prune`, tolerance 0; K4.6). Default false: quantizing keeps the source
30
+ * topology, so a native FLOAT image quantizes to native's Fp8/FpN layout.
31
+ */
32
+ collapse?: boolean;
33
+ }
34
+ /** Quantizes a FLOAT grid image (or built grid) to Fp8/FpN. Returns a new image. */
35
+ 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. */
37
+ export declare function vdbQuantizeDetailed(input: Uint32Array | VDBBuiltGrid, mode: VDBQuantizeMode, tolerance?: number, options?: VDBQuantizeOptions): VDBBuiltGrid;
38
+ /**
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.
42
+ */
43
+ export declare function vdbCollapseGrid(input: Uint32Array | VDBBuiltGrid): VDBBuiltGrid;