@pmndrs/vdb 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (570) hide show
  1. package/CHANGELOG.md +727 -0
  2. package/LICENSE +21 -0
  3. package/README.md +496 -2
  4. package/THIRD_PARTY_NOTICES.md +315 -0
  5. package/dist/core/compute/atlas.d.ts +102 -0
  6. package/dist/core/compute/atlas.js +103 -0
  7. package/dist/core/compute/atlas.js.map +1 -0
  8. package/dist/core/compute/index.d.ts +13 -0
  9. package/dist/core/compute/index.js +9 -0
  10. package/dist/core/compute/index.js.map +1 -0
  11. package/dist/core/compute/majorant-build.d.ts +45 -0
  12. package/dist/core/compute/majorant-build.js +193 -0
  13. package/dist/core/compute/majorant-build.js.map +1 -0
  14. package/dist/core/compute/multi-scale.d.ts +155 -0
  15. package/dist/core/compute/multi-scale.js +684 -0
  16. package/dist/core/compute/multi-scale.js.map +1 -0
  17. package/dist/core/compute/pyramid.d.ts +120 -0
  18. package/dist/core/compute/pyramid.js +468 -0
  19. package/dist/core/compute/pyramid.js.map +1 -0
  20. package/dist/core/compute/shared.d.ts +116 -0
  21. package/dist/core/compute/shared.js +211 -0
  22. package/dist/core/compute/shared.js.map +1 -0
  23. package/dist/core/compute/stats.d.ts +78 -0
  24. package/dist/core/compute/stats.js +193 -0
  25. package/dist/core/compute/stats.js.map +1 -0
  26. package/dist/core/compute/value-transform.d.ts +30 -0
  27. package/dist/core/compute/value-transform.js +64 -0
  28. package/dist/core/compute/value-transform.js.map +1 -0
  29. package/dist/core/errors.d.ts +21 -0
  30. package/dist/core/errors.js +17 -0
  31. package/dist/core/errors.js.map +1 -0
  32. package/dist/core/frame/emission.d.ts +85 -0
  33. package/dist/core/frame/emission.js +422 -0
  34. package/dist/core/frame/emission.js.map +1 -0
  35. package/dist/core/frame/environment.d.ts +47 -0
  36. package/dist/core/frame/environment.js +178 -0
  37. package/dist/core/frame/environment.js.map +1 -0
  38. package/dist/core/frame/index.d.ts +39 -0
  39. package/dist/core/frame/index.js +27 -0
  40. package/dist/core/frame/index.js.map +1 -0
  41. package/dist/core/frame/kernels.d.ts +115 -0
  42. package/dist/core/frame/kernels.js +496 -0
  43. package/dist/core/frame/kernels.js.map +1 -0
  44. package/dist/core/frame/limits.d.ts +67 -0
  45. package/dist/core/frame/limits.js +109 -0
  46. package/dist/core/frame/limits.js.map +1 -0
  47. package/dist/core/frame/phase.d.ts +17 -0
  48. package/dist/core/frame/phase.js +53 -0
  49. package/dist/core/frame/phase.js.map +1 -0
  50. package/dist/core/frame/pipelines.d.ts +49 -0
  51. package/dist/core/frame/pipelines.js +147 -0
  52. package/dist/core/frame/pipelines.js.map +1 -0
  53. package/dist/core/frame/renderer.d.ts +122 -0
  54. package/dist/core/frame/renderer.js +1712 -0
  55. package/dist/core/frame/renderer.js.map +1 -0
  56. package/dist/core/frame/resources.d.ts +71 -0
  57. package/dist/core/frame/resources.js +100 -0
  58. package/dist/core/frame/resources.js.map +1 -0
  59. package/dist/core/frame/scattering.d.ts +97 -0
  60. package/dist/core/frame/scattering.js +332 -0
  61. package/dist/core/frame/scattering.js.map +1 -0
  62. package/dist/core/frame/settings.d.ts +243 -0
  63. package/dist/core/frame/settings.js +67 -0
  64. package/dist/core/frame/settings.js.map +1 -0
  65. package/dist/core/frame/shadows.d.ts +55 -0
  66. package/dist/core/frame/shadows.js +460 -0
  67. package/dist/core/frame/shadows.js.map +1 -0
  68. package/dist/core/frame/types.d.ts +415 -0
  69. package/dist/core/frame/types.js +49 -0
  70. package/dist/core/frame/types.js.map +1 -0
  71. package/dist/core/frame/uniforms.d.ts +105 -0
  72. package/dist/core/frame/uniforms.js +276 -0
  73. package/dist/core/frame/uniforms.js.map +1 -0
  74. package/dist/core/frame/wgsl/chunks.d.ts +4 -0
  75. package/dist/core/frame/wgsl/chunks.js +728 -0
  76. package/dist/core/frame/wgsl/chunks.js.map +1 -0
  77. package/dist/core/frame/wgsl/emission.d.ts +82 -0
  78. package/dist/core/frame/wgsl/emission.js +353 -0
  79. package/dist/core/frame/wgsl/emission.js.map +1 -0
  80. package/dist/core/frame/wgsl/environment.d.ts +42 -0
  81. package/dist/core/frame/wgsl/environment.js +711 -0
  82. package/dist/core/frame/wgsl/environment.js.map +1 -0
  83. package/dist/core/frame/wgsl/gather.d.ts +55 -0
  84. package/dist/core/frame/wgsl/gather.js +850 -0
  85. package/dist/core/frame/wgsl/gather.js.map +1 -0
  86. package/dist/core/frame/wgsl/integrate.d.ts +78 -0
  87. package/dist/core/frame/wgsl/integrate.js +213 -0
  88. package/dist/core/frame/wgsl/integrate.js.map +1 -0
  89. package/dist/core/frame/wgsl/lighting.d.ts +103 -0
  90. package/dist/core/frame/wgsl/lighting.js +1636 -0
  91. package/dist/core/frame/wgsl/lighting.js.map +1 -0
  92. package/dist/core/frame/wgsl/occluders.d.ts +20 -0
  93. package/dist/core/frame/wgsl/occluders.js +95 -0
  94. package/dist/core/frame/wgsl/occluders.js.map +1 -0
  95. package/dist/core/frame/wgsl/resolve.d.ts +19 -0
  96. package/dist/core/frame/wgsl/resolve.js +205 -0
  97. package/dist/core/frame/wgsl/resolve.js.map +1 -0
  98. package/dist/core/frame/wgsl/shadows.d.ts +35 -0
  99. package/dist/core/frame/wgsl/shadows.js +328 -0
  100. package/dist/core/frame/wgsl/shadows.js.map +1 -0
  101. package/dist/core/half.d.ts +11 -0
  102. package/dist/core/half.js +22 -0
  103. package/dist/core/half.js.map +1 -0
  104. package/dist/core/index.d.ts +52 -0
  105. package/dist/core/index.js +46 -0
  106. package/dist/core/index.js.map +1 -0
  107. package/dist/core/internal.d.ts +31 -0
  108. package/dist/core/internal.js +32 -0
  109. package/dist/core/internal.js.map +1 -0
  110. package/dist/core/pool/affine.d.ts +34 -0
  111. package/dist/core/pool/affine.js +100 -0
  112. package/dist/core/pool/affine.js.map +1 -0
  113. package/dist/core/pool/allocator.d.ts +32 -0
  114. package/dist/core/pool/allocator.js +81 -0
  115. package/dist/core/pool/allocator.js.map +1 -0
  116. package/dist/core/pool/image-header.d.ts +93 -0
  117. package/dist/core/pool/image-header.js +194 -0
  118. package/dist/core/pool/image-header.js.map +1 -0
  119. package/dist/core/pool/layout.d.ts +198 -0
  120. package/dist/core/pool/layout.js +316 -0
  121. package/dist/core/pool/layout.js.map +1 -0
  122. package/dist/core/pool/limits.d.ts +41 -0
  123. package/dist/core/pool/limits.js +80 -0
  124. package/dist/core/pool/limits.js.map +1 -0
  125. package/dist/core/pool/pool.d.ts +384 -0
  126. package/dist/core/pool/pool.js +1184 -0
  127. package/dist/core/pool/pool.js.map +1 -0
  128. package/dist/core/reference/index.d.ts +6 -0
  129. package/dist/core/reference/index.js +7 -0
  130. package/dist/core/reference/index.js.map +1 -0
  131. package/dist/core/reference/renderer.d.ts +105 -0
  132. package/dist/core/reference/renderer.js +474 -0
  133. package/dist/core/reference/renderer.js.map +1 -0
  134. package/dist/core/reference/wgsl.d.ts +65 -0
  135. package/dist/core/reference/wgsl.js +803 -0
  136. package/dist/core/reference/wgsl.js.map +1 -0
  137. package/dist/core/sequence.d.ts +347 -0
  138. package/dist/core/sequence.js +548 -0
  139. package/dist/core/sequence.js.map +1 -0
  140. package/dist/core/source/brick-cache.d.ts +165 -0
  141. package/dist/core/source/brick-cache.js +627 -0
  142. package/dist/core/source/brick-cache.js.map +1 -0
  143. package/dist/core/source/dense-fill.d.ts +53 -0
  144. package/dist/core/source/dense-fill.js +377 -0
  145. package/dist/core/source/dense-fill.js.map +1 -0
  146. package/dist/core/source/dense.d.ts +50 -0
  147. package/dist/core/source/dense.js +384 -0
  148. package/dist/core/source/dense.js.map +1 -0
  149. package/dist/core/source/sparse-wgsl.d.ts +92 -0
  150. package/dist/core/source/sparse-wgsl.js +481 -0
  151. package/dist/core/source/sparse-wgsl.js.map +1 -0
  152. package/dist/core/source/sparse.d.ts +192 -0
  153. package/dist/core/source/sparse.js +762 -0
  154. package/dist/core/source/sparse.js.map +1 -0
  155. package/dist/core/source/types.d.ts +120 -0
  156. package/dist/core/source/types.js +9 -0
  157. package/dist/core/source/types.js.map +1 -0
  158. package/dist/core/surface/index.d.ts +10 -0
  159. package/dist/core/surface/index.js +9 -0
  160. package/dist/core/surface/index.js.map +1 -0
  161. package/dist/core/surface/level-set-pass.d.ts +140 -0
  162. package/dist/core/surface/level-set-pass.js +291 -0
  163. package/dist/core/surface/level-set-pass.js.map +1 -0
  164. package/dist/core/surface/level-set-wgsl.d.ts +46 -0
  165. package/dist/core/surface/level-set-wgsl.js +99 -0
  166. package/dist/core/surface/level-set-wgsl.js.map +1 -0
  167. package/dist/core/surface/points.d.ts +109 -0
  168. package/dist/core/surface/points.js +226 -0
  169. package/dist/core/surface/points.js.map +1 -0
  170. package/dist/core/types.d.ts +37 -0
  171. package/dist/core/types.js +32 -0
  172. package/dist/core/types.js.map +1 -0
  173. package/dist/core/wgsl/api.d.ts +65 -0
  174. package/dist/core/wgsl/api.js +546 -0
  175. package/dist/core/wgsl/api.js.map +1 -0
  176. package/dist/core/wgsl/generate.d.ts +90 -0
  177. package/dist/core/wgsl/generate.js +678 -0
  178. package/dist/core/wgsl/generate.js.map +1 -0
  179. package/dist/core/wgsl/lean.d.ts +50 -0
  180. package/dist/core/wgsl/lean.js +327 -0
  181. package/dist/core/wgsl/lean.js.map +1 -0
  182. package/dist/core/wgsl/level-set.d.ts +58 -0
  183. package/dist/core/wgsl/level-set.js +200 -0
  184. package/dist/core/wgsl/level-set.js.map +1 -0
  185. package/dist/core/wgsl/majorant.d.ts +62 -0
  186. package/dist/core/wgsl/majorant.js +381 -0
  187. package/dist/core/wgsl/majorant.js.map +1 -0
  188. package/dist/core/wgsl/pnanovdb.chunks.generated.d.ts +14 -0
  189. package/dist/core/wgsl/pnanovdb.chunks.generated.js +333 -0
  190. package/dist/core/wgsl/pnanovdb.chunks.generated.js.map +1 -0
  191. package/dist/core/wgsl/reserved.d.ts +9 -0
  192. package/dist/core/wgsl/reserved.js +26 -0
  193. package/dist/core/wgsl/reserved.js.map +1 -0
  194. package/dist/core/wgsl/types.d.ts +198 -0
  195. package/dist/core/wgsl/types.js +2 -0
  196. package/dist/core/wgsl/types.js.map +1 -0
  197. package/dist/three/coarse-first.d.ts +207 -0
  198. package/dist/three/coarse-first.js +205 -0
  199. package/dist/three/coarse-first.js.map +1 -0
  200. package/dist/three/compute.d.ts +73 -0
  201. package/dist/three/compute.js +66 -0
  202. package/dist/three/compute.js.map +1 -0
  203. package/dist/three/device.d.ts +66 -0
  204. package/dist/three/device.js +62 -0
  205. package/dist/three/device.js.map +1 -0
  206. package/dist/three/frame/core-environment.d.ts +38 -0
  207. package/dist/three/frame/core-environment.js +154 -0
  208. package/dist/three/frame/core-environment.js.map +1 -0
  209. package/dist/three/frame/core-integrate-material.d.ts +34 -0
  210. package/dist/three/frame/core-integrate-material.js +162 -0
  211. package/dist/three/frame/core-integrate-material.js.map +1 -0
  212. package/dist/three/frame/core-occluders.d.ts +53 -0
  213. package/dist/three/frame/core-occluders.js +193 -0
  214. package/dist/three/frame/core-occluders.js.map +1 -0
  215. package/dist/three/frame/core-structs.d.ts +34 -0
  216. package/dist/three/frame/core-structs.js +61 -0
  217. package/dist/three/frame/core-structs.js.map +1 -0
  218. package/dist/three/frame/core-textures.d.ts +41 -0
  219. package/dist/three/frame/core-textures.js +114 -0
  220. package/dist/three/frame/core-textures.js.map +1 -0
  221. package/dist/three/frame/emission-light.d.ts +117 -0
  222. package/dist/three/frame/emission-light.js +276 -0
  223. package/dist/three/frame/emission-light.js.map +1 -0
  224. package/dist/three/frame/index.d.ts +19 -0
  225. package/dist/three/frame/index.js +15 -0
  226. package/dist/three/frame/index.js.map +1 -0
  227. package/dist/three/frame/medium.d.ts +33 -0
  228. package/dist/three/frame/medium.js +29 -0
  229. package/dist/three/frame/medium.js.map +1 -0
  230. package/dist/three/frame/renderer.d.ts +97 -0
  231. package/dist/three/frame/renderer.js +480 -0
  232. package/dist/three/frame/renderer.js.map +1 -0
  233. package/dist/three/frame/spectrum.d.ts +4 -0
  234. package/dist/three/frame/spectrum.js +15 -0
  235. package/dist/three/frame/spectrum.js.map +1 -0
  236. package/dist/three/frame/three-internals.d.ts +60 -0
  237. package/dist/three/frame/three-internals.js +152 -0
  238. package/dist/three/frame/three-internals.js.map +1 -0
  239. package/dist/three/frame/volume-shadows.d.ts +139 -0
  240. package/dist/three/frame/volume-shadows.js +403 -0
  241. package/dist/three/frame/volume-shadows.js.map +1 -0
  242. package/dist/three/frame/volume.d.ts +230 -0
  243. package/dist/three/frame/volume.js +268 -0
  244. package/dist/three/frame/volume.js.map +1 -0
  245. package/dist/three/grid-node.d.ts +229 -0
  246. package/dist/three/grid-node.js +545 -0
  247. package/dist/three/grid-node.js.map +1 -0
  248. package/dist/three/index.d.ts +52 -0
  249. package/dist/three/index.js +58 -0
  250. package/dist/three/index.js.map +1 -0
  251. package/dist/three/internal.d.ts +20 -0
  252. package/dist/three/internal.js +18 -0
  253. package/dist/three/internal.js.map +1 -0
  254. package/dist/three/level-set-material.d.ts +185 -0
  255. package/dist/three/level-set-material.js +241 -0
  256. package/dist/three/level-set-material.js.map +1 -0
  257. package/dist/three/level-set-physical-material.d.ts +154 -0
  258. package/dist/three/level-set-physical-material.js +253 -0
  259. package/dist/three/level-set-physical-material.js.map +1 -0
  260. package/dist/three/level-set-velocity.d.ts +94 -0
  261. package/dist/three/level-set-velocity.js +208 -0
  262. package/dist/three/level-set-velocity.js.map +1 -0
  263. package/dist/three/material.d.ts +324 -0
  264. package/dist/three/material.js +502 -0
  265. package/dist/three/material.js.map +1 -0
  266. package/dist/three/points.d.ts +140 -0
  267. package/dist/three/points.js +261 -0
  268. package/dist/three/points.js.map +1 -0
  269. package/dist/three/sparse-source.d.ts +165 -0
  270. package/dist/three/sparse-source.js +405 -0
  271. package/dist/three/sparse-source.js.map +1 -0
  272. package/dist/three/volume-source.d.ts +22 -0
  273. package/dist/three/volume-source.js +110 -0
  274. package/dist/three/volume-source.js.map +1 -0
  275. package/dist/tools/cpu/brick-atlas.d.ts +36 -0
  276. package/dist/tools/cpu/brick-atlas.js +129 -0
  277. package/dist/tools/cpu/brick-atlas.js.map +1 -0
  278. package/dist/tools/cpu/compute.d.ts +116 -0
  279. package/dist/tools/cpu/compute.js +239 -0
  280. package/dist/tools/cpu/compute.js.map +1 -0
  281. package/dist/tools/cpu/lean-reads.d.ts +81 -0
  282. package/dist/tools/cpu/lean-reads.js +262 -0
  283. package/dist/tools/cpu/lean-reads.js.map +1 -0
  284. package/dist/tools/cpu/level-set.d.ts +111 -0
  285. package/dist/tools/cpu/level-set.js +313 -0
  286. package/dist/tools/cpu/level-set.js.map +1 -0
  287. package/dist/tools/cpu/majorant.d.ts +265 -0
  288. package/dist/tools/cpu/majorant.js +541 -0
  289. package/dist/tools/cpu/majorant.js.map +1 -0
  290. package/dist/tools/cpu/march.d.ts +297 -0
  291. package/dist/tools/cpu/march.js +726 -0
  292. package/dist/tools/cpu/march.js.map +1 -0
  293. package/dist/tools/cpu/mesh-decimate.d.ts +124 -0
  294. package/dist/tools/cpu/mesh-decimate.js +1225 -0
  295. package/dist/tools/cpu/mesh-decimate.js.map +1 -0
  296. package/dist/tools/cpu/points.d.ts +29 -0
  297. package/dist/tools/cpu/points.js +38 -0
  298. package/dist/tools/cpu/points.js.map +1 -0
  299. package/dist/tools/cpu/probe-coords.d.ts +70 -0
  300. package/dist/tools/cpu/probe-coords.js +116 -0
  301. package/dist/tools/cpu/probe-coords.js.map +1 -0
  302. package/dist/tools/cpu/read-value.d.ts +44 -0
  303. package/dist/tools/cpu/read-value.js +351 -0
  304. package/dist/tools/cpu/read-value.js.map +1 -0
  305. package/dist/tools/cpu/sample-trilinear.d.ts +43 -0
  306. package/dist/tools/cpu/sample-trilinear.js +168 -0
  307. package/dist/tools/cpu/sample-trilinear.js.map +1 -0
  308. package/dist/tools/cpu/stride-tables.d.ts +56 -0
  309. package/dist/tools/cpu/stride-tables.generated.d.ts +1059 -0
  310. package/dist/tools/cpu/stride-tables.generated.js +1267 -0
  311. package/dist/tools/cpu/stride-tables.generated.js.map +1 -0
  312. package/dist/tools/cpu/stride-tables.js +78 -0
  313. package/dist/tools/cpu/stride-tables.js.map +1 -0
  314. package/dist/tools/cpu/surface-nets.d.ts +90 -0
  315. package/dist/tools/cpu/surface-nets.js +597 -0
  316. package/dist/tools/cpu/surface-nets.js.map +1 -0
  317. package/dist/tools/errors.d.ts +66 -0
  318. package/dist/tools/errors.js +67 -0
  319. package/dist/tools/errors.js.map +1 -0
  320. package/dist/tools/frame/ambient.d.ts +98 -0
  321. package/dist/tools/frame/ambient.js +274 -0
  322. package/dist/tools/frame/ambient.js.map +1 -0
  323. package/dist/tools/frame/blackbody.d.ts +57 -0
  324. package/dist/tools/frame/blackbody.js +151 -0
  325. package/dist/tools/frame/blackbody.js.map +1 -0
  326. package/dist/tools/frame/brick-cache.d.ts +165 -0
  327. package/dist/tools/frame/brick-cache.js +326 -0
  328. package/dist/tools/frame/brick-cache.js.map +1 -0
  329. package/dist/tools/frame/emission.d.ts +137 -0
  330. package/dist/tools/frame/emission.js +290 -0
  331. package/dist/tools/frame/emission.js.map +1 -0
  332. package/dist/tools/frame/environment-gpu.d.ts +111 -0
  333. package/dist/tools/frame/environment-gpu.js +280 -0
  334. package/dist/tools/frame/environment-gpu.js.map +1 -0
  335. package/dist/tools/frame/environment.d.ts +106 -0
  336. package/dist/tools/frame/environment.js +272 -0
  337. package/dist/tools/frame/environment.js.map +1 -0
  338. package/dist/tools/frame/froxel.d.ts +58 -0
  339. package/dist/tools/frame/froxel.js +115 -0
  340. package/dist/tools/frame/froxel.js.map +1 -0
  341. package/dist/tools/frame/grid.d.ts +392 -0
  342. package/dist/tools/frame/grid.js +802 -0
  343. package/dist/tools/frame/grid.js.map +1 -0
  344. package/dist/tools/frame/index.d.ts +150 -0
  345. package/dist/tools/frame/index.js +389 -0
  346. package/dist/tools/frame/index.js.map +1 -0
  347. package/dist/tools/frame/medium.d.ts +77 -0
  348. package/dist/tools/frame/medium.js +101 -0
  349. package/dist/tools/frame/medium.js.map +1 -0
  350. package/dist/tools/frame/mie-table.d.ts +6 -0
  351. package/dist/tools/frame/mie-table.js +16 -0
  352. package/dist/tools/frame/mie-table.js.map +1 -0
  353. package/dist/tools/frame/mie.d.ts +63 -0
  354. package/dist/tools/frame/mie.js +194 -0
  355. package/dist/tools/frame/mie.js.map +1 -0
  356. package/dist/tools/frame/mlp-nn.d.ts +36 -0
  357. package/dist/tools/frame/mlp-nn.js +159 -0
  358. package/dist/tools/frame/mlp-nn.js.map +1 -0
  359. package/dist/tools/frame/mlp-tza.d.ts +29 -0
  360. package/dist/tools/frame/mlp-tza.js +186 -0
  361. package/dist/tools/frame/mlp-tza.js.map +1 -0
  362. package/dist/tools/frame/mlp.d.ts +183 -0
  363. package/dist/tools/frame/mlp.js +434 -0
  364. package/dist/tools/frame/mlp.js.map +1 -0
  365. package/dist/tools/frame/ms-exit.d.ts +42 -0
  366. package/dist/tools/frame/ms-exit.js +90 -0
  367. package/dist/tools/frame/ms-exit.js.map +1 -0
  368. package/dist/tools/frame/multi-scale.d.ts +152 -0
  369. package/dist/tools/frame/multi-scale.js +302 -0
  370. package/dist/tools/frame/multi-scale.js.map +1 -0
  371. package/dist/tools/frame/neural-weights.d.ts +10 -0
  372. package/dist/tools/frame/neural-weights.js +244 -0
  373. package/dist/tools/frame/neural-weights.js.map +1 -0
  374. package/dist/tools/frame/neural.d.ts +80 -0
  375. package/dist/tools/frame/neural.js +150 -0
  376. package/dist/tools/frame/neural.js.map +1 -0
  377. package/dist/tools/frame/occluders.d.ts +51 -0
  378. package/dist/tools/frame/occluders.js +72 -0
  379. package/dist/tools/frame/occluders.js.map +1 -0
  380. package/dist/tools/frame/pyramid-layout.d.ts +55 -0
  381. package/dist/tools/frame/pyramid-layout.js +100 -0
  382. package/dist/tools/frame/pyramid-layout.js.map +1 -0
  383. package/dist/tools/frame/shadows.d.ts +190 -0
  384. package/dist/tools/frame/shadows.js +468 -0
  385. package/dist/tools/frame/shadows.js.map +1 -0
  386. package/dist/tools/frame/sparse.d.ts +147 -0
  387. package/dist/tools/frame/sparse.js +432 -0
  388. package/dist/tools/frame/sparse.js.map +1 -0
  389. package/dist/tools/frame/spectral-stack.d.ts +159 -0
  390. package/dist/tools/frame/spectral-stack.js +391 -0
  391. package/dist/tools/frame/spectral-stack.js.map +1 -0
  392. package/dist/tools/frame/spectral.d.ts +222 -0
  393. package/dist/tools/frame/spectral.js +572 -0
  394. package/dist/tools/frame/spectral.js.map +1 -0
  395. package/dist/tools/frame/stack.d.ts +115 -0
  396. package/dist/tools/frame/stack.js +290 -0
  397. package/dist/tools/frame/stack.js.map +1 -0
  398. package/dist/tools/frame/view.d.ts +131 -0
  399. package/dist/tools/frame/view.js +337 -0
  400. package/dist/tools/frame/view.js.map +1 -0
  401. package/dist/tools/index.d.ts +157 -0
  402. package/dist/tools/index.js +132 -0
  403. package/dist/tools/index.js.map +1 -0
  404. package/dist/tools/internal.d.ts +87 -0
  405. package/dist/tools/internal.js +85 -0
  406. package/dist/tools/internal.js.map +1 -0
  407. package/dist/tools/nanovdb/build-from-vdb.d.ts +59 -0
  408. package/dist/tools/nanovdb/build-from-vdb.js +100 -0
  409. package/dist/tools/nanovdb/build-from-vdb.js.map +1 -0
  410. package/dist/tools/nanovdb/bytes.d.ts +233 -0
  411. package/dist/tools/nanovdb/bytes.js +388 -0
  412. package/dist/tools/nanovdb/bytes.js.map +1 -0
  413. package/dist/tools/nanovdb/coarse-first.d.ts +78 -0
  414. package/dist/tools/nanovdb/coarse-first.js +92 -0
  415. package/dist/tools/nanovdb/coarse-first.js.map +1 -0
  416. package/dist/tools/nanovdb/half.d.ts +22 -0
  417. package/dist/tools/nanovdb/half.js +73 -0
  418. package/dist/tools/nanovdb/half.js.map +1 -0
  419. package/dist/tools/nanovdb/index.d.ts +34 -0
  420. package/dist/tools/nanovdb/index.js +25 -0
  421. package/dist/tools/nanovdb/index.js.map +1 -0
  422. package/dist/tools/nanovdb/inspect.d.ts +33 -0
  423. package/dist/tools/nanovdb/inspect.js +70 -0
  424. package/dist/tools/nanovdb/inspect.js.map +1 -0
  425. package/dist/tools/nanovdb/leaf-codec.d.ts +119 -0
  426. package/dist/tools/nanovdb/leaf-codec.js +356 -0
  427. package/dist/tools/nanovdb/leaf-codec.js.map +1 -0
  428. package/dist/tools/nanovdb/quantize.d.ts +72 -0
  429. package/dist/tools/nanovdb/quantize.js +329 -0
  430. package/dist/tools/nanovdb/quantize.js.map +1 -0
  431. package/dist/tools/nanovdb/resample.d.ts +177 -0
  432. package/dist/tools/nanovdb/resample.js +692 -0
  433. package/dist/tools/nanovdb/resample.js.map +1 -0
  434. package/dist/tools/nanovdb/serialize.d.ts +176 -0
  435. package/dist/tools/nanovdb/serialize.js +439 -0
  436. package/dist/tools/nanovdb/serialize.js.map +1 -0
  437. package/dist/tools/nanovdb/stats.d.ts +87 -0
  438. package/dist/tools/nanovdb/stats.js +225 -0
  439. package/dist/tools/nanovdb/stats.js.map +1 -0
  440. package/dist/tools/nanovdb/transform.d.ts +30 -0
  441. package/dist/tools/nanovdb/transform.js +94 -0
  442. package/dist/tools/nanovdb/transform.js.map +1 -0
  443. package/dist/tools/nanovdb/tree.d.ts +186 -0
  444. package/dist/tools/nanovdb/tree.js +530 -0
  445. package/dist/tools/nanovdb/tree.js.map +1 -0
  446. package/dist/tools/nanovdb/write-nvdb.d.ts +74 -0
  447. package/dist/tools/nanovdb/write-nvdb.js +290 -0
  448. package/dist/tools/nanovdb/write-nvdb.js.map +1 -0
  449. package/dist/tools/nvdb-file.d.ts +265 -0
  450. package/dist/tools/nvdb-file.js +763 -0
  451. package/dist/tools/nvdb-file.js.map +1 -0
  452. package/dist/tools/nvdb-stream.d.ts +154 -0
  453. package/dist/tools/nvdb-stream.js +409 -0
  454. package/dist/tools/nvdb-stream.js.map +1 -0
  455. package/dist/tools/reference/analytic.d.ts +41 -0
  456. package/dist/tools/reference/analytic.js +95 -0
  457. package/dist/tools/reference/analytic.js.map +1 -0
  458. package/dist/tools/reference/environment.d.ts +62 -0
  459. package/dist/tools/reference/environment.js +154 -0
  460. package/dist/tools/reference/environment.js.map +1 -0
  461. package/dist/tools/reference/index.d.ts +12 -0
  462. package/dist/tools/reference/index.js +13 -0
  463. package/dist/tools/reference/index.js.map +1 -0
  464. package/dist/tools/reference/media.d.ts +14 -0
  465. package/dist/tools/reference/media.js +30 -0
  466. package/dist/tools/reference/media.js.map +1 -0
  467. package/dist/tools/reference/rng.d.ts +20 -0
  468. package/dist/tools/reference/rng.js +30 -0
  469. package/dist/tools/reference/rng.js.map +1 -0
  470. package/dist/tools/reference/scene.d.ts +312 -0
  471. package/dist/tools/reference/scene.js +169 -0
  472. package/dist/tools/reference/scene.js.map +1 -0
  473. package/dist/tools/reference/tables.d.ts +98 -0
  474. package/dist/tools/reference/tables.js +264 -0
  475. package/dist/tools/reference/tables.js.map +1 -0
  476. package/dist/tools/reference/trace.d.ts +160 -0
  477. package/dist/tools/reference/trace.js +497 -0
  478. package/dist/tools/reference/trace.js.map +1 -0
  479. package/dist/tools/vdb/bit-utils.d.ts +20 -0
  480. package/dist/tools/vdb/bit-utils.js +42 -0
  481. package/dist/tools/vdb/bit-utils.js.map +1 -0
  482. package/dist/tools/vdb/blosc-write.d.ts +43 -0
  483. package/dist/tools/vdb/blosc-write.js +197 -0
  484. package/dist/tools/vdb/blosc-write.js.map +1 -0
  485. package/dist/tools/vdb/blosc.d.ts +86 -0
  486. package/dist/tools/vdb/blosc.js +287 -0
  487. package/dist/tools/vdb/blosc.js.map +1 -0
  488. package/dist/tools/vdb/blosclz.d.ts +33 -0
  489. package/dist/tools/vdb/blosclz.js +112 -0
  490. package/dist/tools/vdb/blosclz.js.map +1 -0
  491. package/dist/tools/vdb/byte-reader.d.ts +50 -0
  492. package/dist/tools/vdb/byte-reader.js +161 -0
  493. package/dist/tools/vdb/byte-reader.js.map +1 -0
  494. package/dist/tools/vdb/compression.d.ts +81 -0
  495. package/dist/tools/vdb/compression.js +260 -0
  496. package/dist/tools/vdb/compression.js.map +1 -0
  497. package/dist/tools/vdb/errors.d.ts +10 -0
  498. package/dist/tools/vdb/errors.js +11 -0
  499. package/dist/tools/vdb/errors.js.map +1 -0
  500. package/dist/tools/vdb/grid.d.ts +37 -0
  501. package/dist/tools/vdb/grid.js +153 -0
  502. package/dist/tools/vdb/grid.js.map +1 -0
  503. package/dist/tools/vdb/half-float.d.ts +9 -0
  504. package/dist/tools/vdb/half-float.js +24 -0
  505. package/dist/tools/vdb/half-float.js.map +1 -0
  506. package/dist/tools/vdb/index.d.ts +4 -0
  507. package/dist/tools/vdb/index.js +3 -0
  508. package/dist/tools/vdb/index.js.map +1 -0
  509. package/dist/tools/vdb/inflate.d.ts +24 -0
  510. package/dist/tools/vdb/inflate.js +334 -0
  511. package/dist/tools/vdb/inflate.js.map +1 -0
  512. package/dist/tools/vdb/lz4.d.ts +30 -0
  513. package/dist/tools/vdb/lz4.js +228 -0
  514. package/dist/tools/vdb/lz4.js.map +1 -0
  515. package/dist/tools/vdb/metadata.d.ts +17 -0
  516. package/dist/tools/vdb/metadata.js +72 -0
  517. package/dist/tools/vdb/metadata.js.map +1 -0
  518. package/dist/tools/vdb/parse.d.ts +47 -0
  519. package/dist/tools/vdb/parse.js +241 -0
  520. package/dist/tools/vdb/parse.js.map +1 -0
  521. package/dist/tools/vdb/point-render-data.d.ts +79 -0
  522. package/dist/tools/vdb/point-render-data.js +137 -0
  523. package/dist/tools/vdb/point-render-data.js.map +1 -0
  524. package/dist/tools/vdb/points.d.ts +186 -0
  525. package/dist/tools/vdb/points.js +835 -0
  526. package/dist/tools/vdb/points.js.map +1 -0
  527. package/dist/tools/vdb/transform.d.ts +23 -0
  528. package/dist/tools/vdb/transform.js +54 -0
  529. package/dist/tools/vdb/transform.js.map +1 -0
  530. package/dist/tools/vdb/tree.d.ts +111 -0
  531. package/dist/tools/vdb/tree.js +228 -0
  532. package/dist/tools/vdb/tree.js.map +1 -0
  533. package/dist/tools/vdb/types.d.ts +195 -0
  534. package/dist/tools/vdb/types.js +3 -0
  535. package/dist/tools/vdb/types.js.map +1 -0
  536. package/dist/tools/wvdb/bake.d.ts +145 -0
  537. package/dist/tools/wvdb/bake.js +361 -0
  538. package/dist/tools/wvdb/bake.js.map +1 -0
  539. package/dist/tools/wvdb/dense.d.ts +191 -0
  540. package/dist/tools/wvdb/dense.js +368 -0
  541. package/dist/tools/wvdb/dense.js.map +1 -0
  542. package/dist/tools/wvdb/format.d.ts +220 -0
  543. package/dist/tools/wvdb/format.js +306 -0
  544. package/dist/tools/wvdb/format.js.map +1 -0
  545. package/dist/tools/wvdb/index.d.ts +14 -0
  546. package/dist/tools/wvdb/index.js +15 -0
  547. package/dist/tools/wvdb/index.js.map +1 -0
  548. package/dist/tools/wvdb/level-set.d.ts +56 -0
  549. package/dist/tools/wvdb/level-set.js +153 -0
  550. package/dist/tools/wvdb/level-set.js.map +1 -0
  551. package/dist/tools/wvdb/nanovdb.d.ts +59 -0
  552. package/dist/tools/wvdb/nanovdb.js +64 -0
  553. package/dist/tools/wvdb/nanovdb.js.map +1 -0
  554. package/dist/tools/wvdb/partial.d.ts +74 -0
  555. package/dist/tools/wvdb/partial.js +233 -0
  556. package/dist/tools/wvdb/partial.js.map +1 -0
  557. package/dist/tools/wvdb/read.d.ts +336 -0
  558. package/dist/tools/wvdb/read.js +766 -0
  559. package/dist/tools/wvdb/read.js.map +1 -0
  560. package/dist/tools/wvdb/sha256.d.ts +7 -0
  561. package/dist/tools/wvdb/sha256.js +76 -0
  562. package/dist/tools/wvdb/sha256.js.map +1 -0
  563. package/dist/tools/wvdb/write.d.ts +149 -0
  564. package/dist/tools/wvdb/write.js +403 -0
  565. package/dist/tools/wvdb/write.js.map +1 -0
  566. package/package.json +83 -4
  567. package/vendor/LICENSE +201 -0
  568. package/vendor/NOTICE +19 -0
  569. package/vendor/VENDOR.md +100 -0
  570. package/vendor/pnanovdb.wgsl +1577 -0
@@ -0,0 +1,388 @@
1
+ /**
2
+ * bytes.ts — the single home for every NanoVDB struct offset/size constant and
3
+ * the low-level little-endian writer used by the serializer. No other module in
4
+ * `nanovdb/` writes a raw byte offset: they go through the named constants and
5
+ * the {@link GridImageWriter} helpers here.
6
+ *
7
+ * ## Provenance of the numbers
8
+ *
9
+ * Every constant below is the ABI-32 value extracted into
10
+ * `packages/vdb/vendor/stride-tables.json` (itself generated from the
11
+ * vendored `PNanoVDB.h`). They are duplicated here as named literals rather than
12
+ * read from that JSON at runtime on purpose: `@pmndrs/vdb/tools` is the pure-TS,
13
+ * browser-first CPU half (decision D3) and must not pull in `node:fs`. To keep
14
+ * the two provably in lockstep, `test/bytes-constants.test.ts` reads
15
+ * stride-tables.json and asserts each constant here equals the extracted value.
16
+ *
17
+ * Only the FLOAT grid type is wired up in this wave; the per-grid-type layout
18
+ * (`FLOAT` block below) is isolated so Fp8/FpN can be added as sibling blocks in
19
+ * the quantization wave without touching the common offsets.
20
+ */
21
+ // ---------------------------------------------------------------------------
22
+ // Magic numbers, versioning, enums (PNANOVDB_* #defines)
23
+ // ---------------------------------------------------------------------------
24
+ /** Grid-image magic `NanoVDB1` (u64, little-endian). This is what the raw grid
25
+ * buffer starts with — what `readValue`/`NvdbFile` sniff for. */
26
+ export const MAGIC_GRID = 0x314244566f6e614en; // "NanoVDB1"
27
+ /** File-header magic `NanoVDB2` (u64) for the segment `.nvdb` container. */
28
+ export const MAGIC_FILE = 0x324244566f6e614en; // "NanoVDB2"
29
+ /** Written into every grid and file header: 32.11.0, as native NanoVDB v14 and the reference header (K7.5a, D37). */
30
+ export const MAJOR_VERSION = 32;
31
+ export const MINOR_VERSION = 11;
32
+ export const PATCH_VERSION = 0;
33
+ /** Packed `Version`: major<<21 | minor<<10 | patch. */
34
+ export const VERSION_PACKED = (MAJOR_VERSION << 21) | (MINOR_VERSION << 10) | PATCH_VERSION;
35
+ export const GRID_TYPE_FLOAT = 1;
36
+ export const GRID_TYPE_FP4 = 13;
37
+ export const GRID_TYPE_FP8 = 14;
38
+ export const GRID_TYPE_FP16 = 15;
39
+ export const GRID_TYPE_FPN = 16;
40
+ /** NanoVDB `GridType::Half`: raw IEEE binary16 values (NanoVDB 13.2, K7.H). */
41
+ export const GRID_TYPE_HALF = 9;
42
+ export const GRID_TYPE_VEC3F = 6;
43
+ export const GRID_CLASS_UNKNOWN = 0;
44
+ export const GRID_CLASS_LEVEL_SET = 1;
45
+ export const GRID_CLASS_FOG_VOLUME = 2;
46
+ export const GRID_CLASS_STAGGERED = 3;
47
+ /**
48
+ * GridData.mFlags for a grid that carries a bbox and full min/max/ave/stddev
49
+ * statistics and is laid out breadth-first — the exact value native
50
+ * `nanovdb_convert` writes for a stats-bearing float FogVolume (verified:
51
+ * `sphere_fog_float.nvdb` carries 0x3e). Bit0 (HasLongGridName) stays clear
52
+ * because we reject names longer than the inline 256-byte field.
53
+ * bit1 HasBBox | bit2 HasMinMax | bit3 HasAverage | bit4 HasStdDeviation |
54
+ * bit5 IsBreadthFirst
55
+ */
56
+ export const GRID_FLAGS_STATS_BBOX_BREADTH_FIRST = 0x3e;
57
+ /**
58
+ * Internal-node (`mFlags`, u64) and leaf (`bbox_dif_and_flags` high byte) flag
59
+ * value written by native `nanovdb_convert` on every stats-bearing node
60
+ * (verified: uppers, lowers and leaves in `sphere_fog_float.nvdb` all carry 2).
61
+ * Neither the CPU (`read-value.ts`) nor WGSL FLOAT readers consult it; we mirror
62
+ * it for structural fidelity with native output.
63
+ */
64
+ export const NODE_FLAG_STATS = 2;
65
+ // ---------------------------------------------------------------------------
66
+ // GridData (672 bytes)
67
+ // ---------------------------------------------------------------------------
68
+ export const GRID_SIZE = 672;
69
+ export const GRID_OFF_MAGIC = 0;
70
+ export const GRID_OFF_CHECKSUM = 8;
71
+ export const GRID_OFF_VERSION = 16;
72
+ export const GRID_OFF_FLAGS = 20;
73
+ export const GRID_OFF_GRID_INDEX = 24;
74
+ export const GRID_OFF_GRID_COUNT = 28;
75
+ export const GRID_OFF_GRID_SIZE = 32;
76
+ export const GRID_OFF_GRID_NAME = 40;
77
+ export const GRID_NAME_MAX = 256; // GridData::MaxNameSize
78
+ export const GRID_OFF_MAP = 296;
79
+ export const GRID_OFF_WORLD_BBOX = 560;
80
+ export const GRID_OFF_VOXEL_SIZE = 608;
81
+ export const GRID_OFF_GRID_CLASS = 632;
82
+ export const GRID_OFF_GRID_TYPE = 636;
83
+ export const GRID_OFF_BLIND_METADATA_OFFSET = 640;
84
+ export const GRID_OFF_BLIND_METADATA_COUNT = 648;
85
+ export const GRID_OFF_DATA0 = 652;
86
+ export const GRID_OFF_DATA1 = 656;
87
+ export const GRID_OFF_DATA2 = 664;
88
+ /**
89
+ * GridData.mChecksum sentinel meaning "no checksum" (NanoVDB `ChecksumMode`
90
+ * Disable == ~uint64_t(0)). We write this rather than a real CRC: neither the
91
+ * CPU reader, the WGSL reader, nor `NvdbFile.fromArrayBuffer` validates the
92
+ * checksum (verified by reading their source — only magic, version and
93
+ * mGridSize are cross-checked), so a disabled checksum round-trips cleanly.
94
+ * Computing the native CRC48/Full checksum is deferred to the nanovdb_convert
95
+ * byte-parity item (see build-from-dense.ts module doc).
96
+ */
97
+ export const CHECKSUM_DISABLED = 0xffffffffffffffffn;
98
+ // Map (affine transform), offsets relative to GRID_OFF_MAP.
99
+ export const MAP_OFF_MATF = 0; // float[9] row-major 3x3
100
+ export const MAP_OFF_INVMATF = 36; // float[9]
101
+ export const MAP_OFF_VECF = 72; // float[3] translation
102
+ export const MAP_OFF_TAPERF = 84; // float
103
+ export const MAP_OFF_MATD = 88; // double[9]
104
+ export const MAP_OFF_INVMATD = 160; // double[9]
105
+ export const MAP_OFF_VECD = 232; // double[3]
106
+ export const MAP_OFF_TAPERD = 256; // double
107
+ export const MAP_SIZE = 264;
108
+ // ---------------------------------------------------------------------------
109
+ // TreeData (64 bytes)
110
+ // ---------------------------------------------------------------------------
111
+ export const TREE_SIZE = 64;
112
+ export const TREE_OFF_NODE_OFFSET_LEAF = 0; // u64, bytes from TreeData to first leaf
113
+ export const TREE_OFF_NODE_OFFSET_LOWER = 8; // u64
114
+ export const TREE_OFF_NODE_OFFSET_UPPER = 16; // u64
115
+ export const TREE_OFF_NODE_OFFSET_ROOT = 24; // u64
116
+ export const TREE_OFF_NODE_COUNT_LEAF = 32; // u32
117
+ export const TREE_OFF_NODE_COUNT_LOWER = 36; // u32
118
+ export const TREE_OFF_NODE_COUNT_UPPER = 40; // u32
119
+ export const TREE_OFF_TILE_COUNT_LOWER = 44; // u32 (active tiles)
120
+ export const TREE_OFF_TILE_COUNT_UPPER = 48; // u32
121
+ export const TREE_OFF_TILE_COUNT_ROOT = 52; // u32
122
+ export const TREE_OFF_VOXEL_COUNT = 56; // u64 (active voxels)
123
+ // ---------------------------------------------------------------------------
124
+ // RootData + RootTile
125
+ // ---------------------------------------------------------------------------
126
+ export const ROOT_OFF_BBOX_MIN = 0; // i32[3]
127
+ export const ROOT_OFF_BBOX_MAX = 12; // i32[3]
128
+ export const ROOT_OFF_TABLE_SIZE = 24; // u32 (tile count)
129
+ export const ROOT_TILE_OFF_KEY = 0; // u64
130
+ export const ROOT_TILE_OFF_CHILD = 8; // i64 (bytes from RootData to child upper node)
131
+ export const ROOT_TILE_OFF_STATE = 16; // u32
132
+ // ---------------------------------------------------------------------------
133
+ // Internal node common offsets (same for upper and lower; masks differ in size)
134
+ // ---------------------------------------------------------------------------
135
+ export const NODE_OFF_BBOX_MIN = 0; // i32[3]
136
+ export const NODE_OFF_BBOX_MAX = 12; // i32[3]
137
+ export const NODE_OFF_FLAGS = 24; // u64
138
+ export const NODE_OFF_VALUE_MASK = 32; // bit array
139
+ export const UPPER_OFF_CHILD_MASK = 4128; // after 32768-bit value mask
140
+ export const UPPER_TABLE_COUNT = 32768; // 32^3
141
+ export const LOWER_OFF_CHILD_MASK = 544; // after 4096-bit value mask
142
+ export const LOWER_TABLE_COUNT = 4096; // 16^3
143
+ // ---------------------------------------------------------------------------
144
+ // Leaf common offsets
145
+ // ---------------------------------------------------------------------------
146
+ export const LEAF_OFF_BBOX_MIN = 0; // i32[3]
147
+ export const LEAF_OFF_BBOX_DIF_AND_FLAGS = 12; // u32: [difX,difY,difZ,flags] bytes
148
+ export const LEAF_OFF_VALUE_MASK = 16; // 512-bit array (64 bytes)
149
+ export const LEAF_TABLE_COUNT = 512; // 8^3
150
+ // ---------------------------------------------------------------------------
151
+ // Quantized-leaf (Fp8/FpN) header layout — `LeafFnBase` (NanoVDB.h). The 96-byte
152
+ // header is common to Fp4/Fp8/Fp16/FpN; the compressed code array follows at 96.
153
+ // Unlike FLOAT (which stores f32 stats), quantized leaves store the affine
154
+ // (mMinimum, mQuantum) pair as f32 and the min/max/ave/dev *statistics* as
155
+ // uint16 codes quantized against that same (min, quantum). Verified against the
156
+ // native box/sphere fp8+fpn fixtures.
157
+ // ---------------------------------------------------------------------------
158
+ export const LEAF_OFF_FP_MINIMUM = 80; // f32 mMinimum (== value at code 0)
159
+ export const LEAF_OFF_FP_QUANTUM = 84; // f32 mQuantum (== (max-min)/((1<<bits)-1))
160
+ export const LEAF_OFF_FP_STAT_MIN = 88; // u16 quantized min of active values
161
+ export const LEAF_OFF_FP_STAT_MAX = 90; // u16
162
+ export const LEAF_OFF_FP_STAT_AVG = 92; // u16
163
+ export const LEAF_OFF_FP_STAT_DEV = 94; // u16
164
+ export const LEAF_OFF_FP_CODES = 96; // start of the packed code array
165
+ export const FP_LEAF_HEADER_SIZE = 96;
166
+ /** FpN leaf `mFlags` (high byte of bbox_dif_and_flags): logBitWidth in bits 5-7,
167
+ * plus the has-bbox bit the native encoder always sets (0x02). Fp8 uses 0x02. */
168
+ export const LEAF_FLAG_HAS_BBOX = 2;
169
+ export const FLOAT_LAYOUT = {
170
+ gridType: GRID_TYPE_FLOAT,
171
+ rootSize: 64,
172
+ rootTileSize: 32,
173
+ rootTileOffValue: 20,
174
+ rootOffBackground: 28,
175
+ rootOffMin: 32,
176
+ rootOffMax: 36,
177
+ rootOffAve: 40,
178
+ rootOffStdDev: 44,
179
+ tableStride: 8,
180
+ valueStrideBits: 32,
181
+ upperSize: 270400,
182
+ upperOffTable: 8256,
183
+ upperOffMin: 8224,
184
+ upperOffMax: 8228,
185
+ upperOffAve: 8232,
186
+ upperOffStdDev: 8236,
187
+ lowerSize: 33856,
188
+ lowerOffTable: 1088,
189
+ lowerOffMin: 1056,
190
+ lowerOffMax: 1060,
191
+ lowerOffAve: 1064,
192
+ lowerOffStdDev: 1068,
193
+ leafSize: 2144,
194
+ leafOffTable: 96,
195
+ leafOffMin: 80,
196
+ leafOffMax: 84,
197
+ leafOffAve: 88,
198
+ leafOffStdDev: 92,
199
+ };
200
+ /**
201
+ * Quantized (Fp8/FpN) grid layout. Root/upper/lower blocks are byte-for-byte
202
+ * identical to FLOAT (their tiles/stats stay f32); only the leaf differs. For
203
+ * Fp8 `leafSize` is a fixed 608 (96 header + 512 one-byte codes). For FpN the
204
+ * leaf is variable-sized (96 + bitWidth*64), so `leafSize` here is the 96-byte
205
+ * base — the real per-leaf size comes from the codec. The `leafOff*` stat
206
+ * offsets are the u16 statistic slots (the codec writes them directly).
207
+ */
208
+ function quantizedLayout(gridType, leafSize) {
209
+ return {
210
+ ...FLOAT_LAYOUT,
211
+ gridType,
212
+ valueStrideBits: 0, // not a uniform stride for quantized leaves
213
+ leafSize,
214
+ leafOffTable: LEAF_OFF_FP_CODES,
215
+ leafOffMin: LEAF_OFF_FP_STAT_MIN,
216
+ leafOffMax: LEAF_OFF_FP_STAT_MAX,
217
+ leafOffAve: LEAF_OFF_FP_STAT_AVG,
218
+ leafOffStdDev: LEAF_OFF_FP_STAT_DEV,
219
+ };
220
+ }
221
+ /** Fp8: fixed 8-bit codes. Leaf = 96-byte header + 512 bytes = 608. */
222
+ export const FP8_LAYOUT = quantizedLayout(GRID_TYPE_FP8, 608);
223
+ /** Fp4: fixed 4-bit codes. Leaf = 96-byte header + 256 bytes = 352. */
224
+ export const FP4_LAYOUT = quantizedLayout(GRID_TYPE_FP4, 352);
225
+ /** Fp16: fixed 16-bit codes. Leaf = 96-byte header + 1024 bytes = 1120. */
226
+ export const FP16_LAYOUT = quantizedLayout(GRID_TYPE_FP16, 1120);
227
+ /** FpN: variable bit-width. `leafSize` is the 96-byte base (see codec). */
228
+ export const FPN_LAYOUT = quantizedLayout(GRID_TYPE_FPN, FP_LEAF_HEADER_SIZE);
229
+ /**
230
+ * Half (K7.H, NanoVDB `GridType::Half`): every value is a raw IEEE binary16
231
+ * (2 bytes) at every level (leaf table, tiles, background); `mMinimum` /
232
+ * `mMaximum` are binary16 too and `mAverage` / `mStdDevi` stay f32
233
+ * (`FloatTraits<Half>` is float). Table slots stay 8 bytes (the value in the
234
+ * low 2 bytes of the union with the i64 child offset); the leaf table is at 96
235
+ * (512 x 2 bytes, leaf 1120). Values from `PNANOVDB_GRID_TYPE_HALF` in the
236
+ * vendored stride tables (unchanged in NanoVDB v14.0.0's PNanoVDB.h).
237
+ */
238
+ export const HALF_LAYOUT = {
239
+ gridType: GRID_TYPE_HALF,
240
+ rootSize: 64,
241
+ rootTileSize: 32,
242
+ rootTileOffValue: 20,
243
+ rootOffBackground: 28,
244
+ rootOffMin: 30,
245
+ rootOffMax: 32,
246
+ rootOffAve: 36,
247
+ rootOffStdDev: 40,
248
+ tableStride: 8,
249
+ valueStrideBits: 16,
250
+ upperSize: 270400,
251
+ upperOffTable: 8256,
252
+ upperOffMin: 8224,
253
+ upperOffMax: 8226,
254
+ upperOffAve: 8228,
255
+ upperOffStdDev: 8232,
256
+ lowerSize: 33856,
257
+ lowerOffTable: 1088,
258
+ lowerOffMin: 1056,
259
+ lowerOffMax: 1058,
260
+ lowerOffAve: 1060,
261
+ lowerOffStdDev: 1064,
262
+ leafSize: 1120,
263
+ leafOffTable: 96,
264
+ leafOffMin: 80,
265
+ leafOffMax: 82,
266
+ leafOffAve: 84,
267
+ leafOffStdDev: 88,
268
+ };
269
+ /**
270
+ * Vec3f (K4.2): every value is 3 f32 (12 bytes); `mMinimum`/`mMaximum` are
271
+ * Vec3f and `mAverage`/`mStdDevi` stay f32 (`FloatTraits<Vec3f>` is float).
272
+ * Internal-node table slots are 16 bytes (the union of a 12-byte value and an
273
+ * i64 child offset); the leaf table is 32-byte aligned at 128. Values from
274
+ * `PNANOVDB_GRID_TYPE_VEC3F` in the vendored stride tables.
275
+ */
276
+ export const VEC3F_LAYOUT = {
277
+ gridType: GRID_TYPE_VEC3F,
278
+ rootSize: 96,
279
+ rootTileSize: 32,
280
+ rootTileOffValue: 20,
281
+ rootOffBackground: 28,
282
+ rootOffMin: 40,
283
+ rootOffMax: 52,
284
+ rootOffAve: 64,
285
+ rootOffStdDev: 68,
286
+ tableStride: 16,
287
+ valueStrideBits: 96,
288
+ upperSize: 532544,
289
+ upperOffTable: 8256,
290
+ upperOffMin: 8224,
291
+ upperOffMax: 8236,
292
+ upperOffAve: 8248,
293
+ upperOffStdDev: 8252,
294
+ lowerSize: 66624,
295
+ lowerOffTable: 1088,
296
+ lowerOffMin: 1056,
297
+ lowerOffMax: 1068,
298
+ lowerOffAve: 1080,
299
+ lowerOffStdDev: 1084,
300
+ leafSize: 6272,
301
+ leafOffTable: 128,
302
+ leafOffMin: 80,
303
+ leafOffMax: 92,
304
+ leafOffAve: 104,
305
+ leafOffStdDev: 108,
306
+ };
307
+ // ---------------------------------------------------------------------------
308
+ // coord -> key / coord -> offset (structural bit math, identical for all types)
309
+ // ---------------------------------------------------------------------------
310
+ /** pnanovdb_coord_to_key — root-tile key for a voxel coord (native-64 branch). */
311
+ export function coordToKey(x, y, z) {
312
+ const iu = BigInt(x >>> 12);
313
+ const ju = BigInt(y >>> 12);
314
+ const ku = BigInt(z >>> 12);
315
+ return ku | (ju << 21n) | (iu << 42n);
316
+ }
317
+ /** pnanovdb_upper_coord_to_offset — lower-table slot within a 32^3 upper. */
318
+ export function upperCoordToOffset(x, y, z) {
319
+ return (((x & 4095) >> 7) << 10) + (((y & 4095) >> 7) << 5) + ((z & 4095) >> 7);
320
+ }
321
+ /** pnanovdb_lower_coord_to_offset — leaf-table slot within a 16^3 lower. */
322
+ export function lowerCoordToOffset(x, y, z) {
323
+ return (((x & 127) >> 3) << 8) + (((y & 127) >> 3) << 4) + ((z & 127) >> 3);
324
+ }
325
+ /** pnanovdb_leaf_coord_to_offset — voxel slot within an 8^3 leaf, 0..511. */
326
+ export function leafCoordToOffset(x, y, z) {
327
+ return ((x & 7) << 6) + ((y & 7) << 3) + (z & 7);
328
+ }
329
+ // ---------------------------------------------------------------------------
330
+ // GridImageWriter — typed little-endian struct writer over one grid image.
331
+ // ---------------------------------------------------------------------------
332
+ /**
333
+ * A thin, endianness-explicit writer over a single grid image's backing
334
+ * `ArrayBuffer`. All NanoVDB integers/floats are little-endian; every setter
335
+ * here passes `true` so the code never repeats the flag. Mask helpers implement
336
+ * `pnanovdb_*_mask` bit addressing (32-bit words, LSB-first within a word).
337
+ */
338
+ export class GridImageWriter {
339
+ bytes;
340
+ u32;
341
+ view;
342
+ constructor(byteLength) {
343
+ if (byteLength % 4 !== 0) {
344
+ throw new Error(`GridImageWriter: byteLength ${byteLength} must be a multiple of 4`);
345
+ }
346
+ const buffer = new ArrayBuffer(byteLength);
347
+ this.bytes = new Uint8Array(buffer);
348
+ this.u32 = new Uint32Array(buffer);
349
+ this.view = new DataView(buffer);
350
+ }
351
+ setU16(off, v) {
352
+ this.view.setUint16(off, v & 0xffff, true);
353
+ }
354
+ setU32(off, v) {
355
+ this.view.setUint32(off, v >>> 0, true);
356
+ }
357
+ setI32(off, v) {
358
+ this.view.setInt32(off, v | 0, true);
359
+ }
360
+ setU64(off, v) {
361
+ this.view.setBigUint64(off, v, true);
362
+ }
363
+ setI64(off, v) {
364
+ this.view.setBigInt64(off, v, true);
365
+ }
366
+ setF32(off, v) {
367
+ this.view.setFloat32(off, v, true);
368
+ }
369
+ setF64(off, v) {
370
+ this.view.setFloat64(off, v, true);
371
+ }
372
+ /** Writes `len` bytes of `src` at `off`, zero-filling nothing beyond it. */
373
+ setBytes(off, src) {
374
+ this.bytes.set(src, off);
375
+ }
376
+ /** Sets bit `bitIndex` of a mask word array whose word 0 starts at `maskBase`. */
377
+ setMaskBit(maskBase, bitIndex) {
378
+ const wordOff = maskBase + 4 * (bitIndex >>> 5);
379
+ this.view.setUint32(wordOff, (this.view.getUint32(wordOff, true) | (1 << (bitIndex & 31))) >>> 0, true);
380
+ }
381
+ /** Copies a whole precomputed 32-bit mask (`words` u32s) to `maskBase`. */
382
+ setMaskWords(maskBase, words) {
383
+ for (let i = 0; i < words.length; i++) {
384
+ this.view.setUint32(maskBase + i * 4, words[i] >>> 0, true);
385
+ }
386
+ }
387
+ }
388
+ //# sourceMappingURL=bytes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bytes.js","sourceRoot":"","sources":["../../../src/tools/nanovdb/bytes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,8EAA8E;AAC9E,yDAAyD;AACzD,8EAA8E;AAE9E;kEACkE;AAClE,MAAM,CAAC,MAAM,UAAU,GAAG,mBAAmB,CAAC,CAAC,aAAa;AAC5D,4EAA4E;AAC5E,MAAM,CAAC,MAAM,UAAU,GAAG,mBAAmB,CAAC,CAAC,aAAa;AAE5D,qHAAqH;AACrH,MAAM,CAAC,MAAM,aAAa,GAAG,EAAE,CAAC;AAChC,MAAM,CAAC,MAAM,aAAa,GAAG,EAAE,CAAC;AAChC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC;AAC/B,uDAAuD;AACvD,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,aAAa,IAAI,EAAE,CAAC,GAAG,CAAC,aAAa,IAAI,EAAE,CAAC,GAAG,aAAa,CAAC;AAE5F,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC;AACjC,MAAM,CAAC,MAAM,aAAa,GAAG,EAAE,CAAC;AAChC,MAAM,CAAC,MAAM,aAAa,GAAG,EAAE,CAAC;AAChC,MAAM,CAAC,MAAM,cAAc,GAAG,EAAE,CAAC;AACjC,MAAM,CAAC,MAAM,aAAa,GAAG,EAAE,CAAC;AA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AC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,EACnE,IAAI,CACL,CAAC;IACJ,CAAC;IAED,2EAA2E;IAC3E,YAAY,CAAC,QAAgB,EAAE,KAAkB;QAC/C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACtC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,GAAG,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC,CAAE,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC;QAC/D,CAAC;IACH,CAAC;CACF","sourcesContent":["/**\n * bytes.ts — the single home for every NanoVDB struct offset/size constant and\n * the low-level little-endian writer used by the serializer. No other module in\n * `nanovdb/` writes a raw byte offset: they go through the named constants and\n * the {@link GridImageWriter} helpers here.\n *\n * ## Provenance of the numbers\n *\n * Every constant below is the ABI-32 value extracted into\n * `packages/vdb/vendor/stride-tables.json` (itself generated from the\n * vendored `PNanoVDB.h`). They are duplicated here as named literals rather than\n * read from that JSON at runtime on purpose: `@pmndrs/vdb/tools` is the pure-TS,\n * browser-first CPU half (decision D3) and must not pull in `node:fs`. To keep\n * the two provably in lockstep, `test/bytes-constants.test.ts` reads\n * stride-tables.json and asserts each constant here equals the extracted value.\n *\n * Only the FLOAT grid type is wired up in this wave; the per-grid-type layout\n * (`FLOAT` block below) is isolated so Fp8/FpN can be added as sibling blocks in\n * the quantization wave without touching the common offsets.\n */\n\n// ---------------------------------------------------------------------------\n// Magic numbers, versioning, enums (PNANOVDB_* #defines)\n// ---------------------------------------------------------------------------\n\n/** Grid-image magic `NanoVDB1` (u64, little-endian). This is what the raw grid\n * buffer starts with — what `readValue`/`NvdbFile` sniff for. */\nexport const MAGIC_GRID = 0x314244566f6e614en; // \"NanoVDB1\"\n/** File-header magic `NanoVDB2` (u64) for the segment `.nvdb` container. */\nexport const MAGIC_FILE = 0x324244566f6e614en; // \"NanoVDB2\"\n\n/** Written into every grid and file header: 32.11.0, as native NanoVDB v14 and the reference header (K7.5a, D37). */\nexport const MAJOR_VERSION = 32;\nexport const MINOR_VERSION = 11;\nexport const PATCH_VERSION = 0;\n/** Packed `Version`: major<<21 | minor<<10 | patch. */\nexport const VERSION_PACKED = (MAJOR_VERSION << 21) | (MINOR_VERSION << 10) | PATCH_VERSION;\n\nexport const GRID_TYPE_FLOAT = 1;\nexport const GRID_TYPE_FP4 = 13;\nexport const GRID_TYPE_FP8 = 14;\nexport const GRID_TYPE_FP16 = 15;\nexport const GRID_TYPE_FPN = 16;\n/** NanoVDB `GridType::Half`: raw IEEE binary16 values (NanoVDB 13.2, K7.H). */\nexport const GRID_TYPE_HALF = 9;\nexport const GRID_TYPE_VEC3F = 6;\nexport const GRID_CLASS_UNKNOWN = 0;\nexport const GRID_CLASS_LEVEL_SET = 1;\nexport const GRID_CLASS_FOG_VOLUME = 2;\nexport const GRID_CLASS_STAGGERED = 3;\n\n/**\n * GridData.mFlags for a grid that carries a bbox and full min/max/ave/stddev\n * statistics and is laid out breadth-first — the exact value native\n * `nanovdb_convert` writes for a stats-bearing float FogVolume (verified:\n * `sphere_fog_float.nvdb` carries 0x3e). Bit0 (HasLongGridName) stays clear\n * because we reject names longer than the inline 256-byte field.\n * bit1 HasBBox | bit2 HasMinMax | bit3 HasAverage | bit4 HasStdDeviation |\n * bit5 IsBreadthFirst\n */\nexport const GRID_FLAGS_STATS_BBOX_BREADTH_FIRST = 0x3e;\n\n/**\n * Internal-node (`mFlags`, u64) and leaf (`bbox_dif_and_flags` high byte) flag\n * value written by native `nanovdb_convert` on every stats-bearing node\n * (verified: uppers, lowers and leaves in `sphere_fog_float.nvdb` all carry 2).\n * Neither the CPU (`read-value.ts`) nor WGSL FLOAT readers consult it; we mirror\n * it for structural fidelity with native output.\n */\nexport const NODE_FLAG_STATS = 2;\n\n// ---------------------------------------------------------------------------\n// GridData (672 bytes)\n// ---------------------------------------------------------------------------\n\nexport const GRID_SIZE = 672;\nexport const GRID_OFF_MAGIC = 0;\nexport const GRID_OFF_CHECKSUM = 8;\nexport const GRID_OFF_VERSION = 16;\nexport const GRID_OFF_FLAGS = 20;\nexport const GRID_OFF_GRID_INDEX = 24;\nexport const GRID_OFF_GRID_COUNT = 28;\nexport const GRID_OFF_GRID_SIZE = 32;\nexport const GRID_OFF_GRID_NAME = 40;\nexport const GRID_NAME_MAX = 256; // GridData::MaxNameSize\nexport const GRID_OFF_MAP = 296;\nexport const GRID_OFF_WORLD_BBOX = 560;\nexport const GRID_OFF_VOXEL_SIZE = 608;\nexport const GRID_OFF_GRID_CLASS = 632;\nexport const GRID_OFF_GRID_TYPE = 636;\nexport const GRID_OFF_BLIND_METADATA_OFFSET = 640;\nexport const GRID_OFF_BLIND_METADATA_COUNT = 648;\nexport const GRID_OFF_DATA0 = 652;\nexport const GRID_OFF_DATA1 = 656;\nexport const GRID_OFF_DATA2 = 664;\n\n/**\n * GridData.mChecksum sentinel meaning \"no checksum\" (NanoVDB `ChecksumMode`\n * Disable == ~uint64_t(0)). We write this rather than a real CRC: neither the\n * CPU reader, the WGSL reader, nor `NvdbFile.fromArrayBuffer` validates the\n * checksum (verified by reading their source — only magic, version and\n * mGridSize are cross-checked), so a disabled checksum round-trips cleanly.\n * Computing the native CRC48/Full checksum is deferred to the nanovdb_convert\n * byte-parity item (see build-from-dense.ts module doc).\n */\nexport const CHECKSUM_DISABLED = 0xffffffffffffffffn;\n\n// Map (affine transform), offsets relative to GRID_OFF_MAP.\nexport const MAP_OFF_MATF = 0; // float[9] row-major 3x3\nexport const MAP_OFF_INVMATF = 36; // float[9]\nexport const MAP_OFF_VECF = 72; // float[3] translation\nexport const MAP_OFF_TAPERF = 84; // float\nexport const MAP_OFF_MATD = 88; // double[9]\nexport const MAP_OFF_INVMATD = 160; // double[9]\nexport const MAP_OFF_VECD = 232; // double[3]\nexport const MAP_OFF_TAPERD = 256; // double\nexport const MAP_SIZE = 264;\n\n// ---------------------------------------------------------------------------\n// TreeData (64 bytes)\n// ---------------------------------------------------------------------------\n\nexport const TREE_SIZE = 64;\nexport const TREE_OFF_NODE_OFFSET_LEAF = 0; // u64, bytes from TreeData to first leaf\nexport const TREE_OFF_NODE_OFFSET_LOWER = 8; // u64\nexport const TREE_OFF_NODE_OFFSET_UPPER = 16; // u64\nexport const TREE_OFF_NODE_OFFSET_ROOT = 24; // u64\nexport const TREE_OFF_NODE_COUNT_LEAF = 32; // u32\nexport const TREE_OFF_NODE_COUNT_LOWER = 36; // u32\nexport const TREE_OFF_NODE_COUNT_UPPER = 40; // u32\nexport const TREE_OFF_TILE_COUNT_LOWER = 44; // u32 (active tiles)\nexport const TREE_OFF_TILE_COUNT_UPPER = 48; // u32\nexport const TREE_OFF_TILE_COUNT_ROOT = 52; // u32\nexport const TREE_OFF_VOXEL_COUNT = 56; // u64 (active voxels)\n\n// ---------------------------------------------------------------------------\n// RootData + RootTile\n// ---------------------------------------------------------------------------\n\nexport const ROOT_OFF_BBOX_MIN = 0; // i32[3]\nexport const ROOT_OFF_BBOX_MAX = 12; // i32[3]\nexport const ROOT_OFF_TABLE_SIZE = 24; // u32 (tile count)\n\nexport const ROOT_TILE_OFF_KEY = 0; // u64\nexport const ROOT_TILE_OFF_CHILD = 8; // i64 (bytes from RootData to child upper node)\nexport const ROOT_TILE_OFF_STATE = 16; // u32\n\n// ---------------------------------------------------------------------------\n// Internal node common offsets (same for upper and lower; masks differ in size)\n// ---------------------------------------------------------------------------\n\nexport const NODE_OFF_BBOX_MIN = 0; // i32[3]\nexport const NODE_OFF_BBOX_MAX = 12; // i32[3]\nexport const NODE_OFF_FLAGS = 24; // u64\nexport const NODE_OFF_VALUE_MASK = 32; // bit array\n\nexport const UPPER_OFF_CHILD_MASK = 4128; // after 32768-bit value mask\nexport const UPPER_TABLE_COUNT = 32768; // 32^3\nexport const LOWER_OFF_CHILD_MASK = 544; // after 4096-bit value mask\nexport const LOWER_TABLE_COUNT = 4096; // 16^3\n\n// ---------------------------------------------------------------------------\n// Leaf common offsets\n// ---------------------------------------------------------------------------\n\nexport const LEAF_OFF_BBOX_MIN = 0; // i32[3]\nexport const LEAF_OFF_BBOX_DIF_AND_FLAGS = 12; // u32: [difX,difY,difZ,flags] bytes\nexport const LEAF_OFF_VALUE_MASK = 16; // 512-bit array (64 bytes)\nexport const LEAF_TABLE_COUNT = 512; // 8^3\n\n// ---------------------------------------------------------------------------\n// Quantized-leaf (Fp8/FpN) header layout — `LeafFnBase` (NanoVDB.h). The 96-byte\n// header is common to Fp4/Fp8/Fp16/FpN; the compressed code array follows at 96.\n// Unlike FLOAT (which stores f32 stats), quantized leaves store the affine\n// (mMinimum, mQuantum) pair as f32 and the min/max/ave/dev *statistics* as\n// uint16 codes quantized against that same (min, quantum). Verified against the\n// native box/sphere fp8+fpn fixtures.\n// ---------------------------------------------------------------------------\n\nexport const LEAF_OFF_FP_MINIMUM = 80; // f32 mMinimum (== value at code 0)\nexport const LEAF_OFF_FP_QUANTUM = 84; // f32 mQuantum (== (max-min)/((1<<bits)-1))\nexport const LEAF_OFF_FP_STAT_MIN = 88; // u16 quantized min of active values\nexport const LEAF_OFF_FP_STAT_MAX = 90; // u16\nexport const LEAF_OFF_FP_STAT_AVG = 92; // u16\nexport const LEAF_OFF_FP_STAT_DEV = 94; // u16\nexport const LEAF_OFF_FP_CODES = 96; // start of the packed code array\nexport const FP_LEAF_HEADER_SIZE = 96;\n\n/** FpN leaf `mFlags` (high byte of bbox_dif_and_flags): logBitWidth in bits 5-7,\n * plus the has-bbox bit the native encoder always sets (0x02). Fp8 uses 0x02. */\nexport const LEAF_FLAG_HAS_BBOX = 2;\n\n// ---------------------------------------------------------------------------\n// Per-grid-type layout (FLOAT). Fp8/FpN add sibling blocks in the next wave.\n// ---------------------------------------------------------------------------\n\n/** Per-grid-type node sizes, stat offsets and table geometry (ABI 32; same in 32.9.1 and 32.11.0). */\nexport interface GridTypeLayout {\n readonly gridType: number;\n readonly rootSize: number;\n readonly rootTileSize: number;\n readonly rootTileOffValue: number;\n readonly rootOffBackground: number;\n readonly rootOffMin: number;\n readonly rootOffMax: number;\n readonly rootOffAve: number;\n readonly rootOffStdDev: number;\n readonly tableStride: number; // bytes per internal-node table slot\n readonly valueStrideBits: number; // bits per leaf value\n readonly upperSize: number;\n readonly upperOffTable: number;\n readonly upperOffMin: number;\n readonly upperOffMax: number;\n readonly upperOffAve: number;\n readonly upperOffStdDev: number;\n readonly lowerSize: number;\n readonly lowerOffTable: number;\n readonly lowerOffMin: number;\n readonly lowerOffMax: number;\n readonly lowerOffAve: number;\n readonly lowerOffStdDev: number;\n readonly leafSize: number;\n readonly leafOffTable: number;\n readonly leafOffMin: number;\n readonly leafOffMax: number;\n readonly leafOffAve: number;\n readonly leafOffStdDev: number;\n}\n\nexport const FLOAT_LAYOUT: GridTypeLayout = {\n gridType: GRID_TYPE_FLOAT,\n rootSize: 64,\n rootTileSize: 32,\n rootTileOffValue: 20,\n rootOffBackground: 28,\n rootOffMin: 32,\n rootOffMax: 36,\n rootOffAve: 40,\n rootOffStdDev: 44,\n tableStride: 8,\n valueStrideBits: 32,\n upperSize: 270400,\n upperOffTable: 8256,\n upperOffMin: 8224,\n upperOffMax: 8228,\n upperOffAve: 8232,\n upperOffStdDev: 8236,\n lowerSize: 33856,\n lowerOffTable: 1088,\n lowerOffMin: 1056,\n lowerOffMax: 1060,\n lowerOffAve: 1064,\n lowerOffStdDev: 1068,\n leafSize: 2144,\n leafOffTable: 96,\n leafOffMin: 80,\n leafOffMax: 84,\n leafOffAve: 88,\n leafOffStdDev: 92,\n};\n\n/**\n * Quantized (Fp8/FpN) grid layout. Root/upper/lower blocks are byte-for-byte\n * identical to FLOAT (their tiles/stats stay f32); only the leaf differs. For\n * Fp8 `leafSize` is a fixed 608 (96 header + 512 one-byte codes). For FpN the\n * leaf is variable-sized (96 + bitWidth*64), so `leafSize` here is the 96-byte\n * base — the real per-leaf size comes from the codec. The `leafOff*` stat\n * offsets are the u16 statistic slots (the codec writes them directly).\n */\nfunction quantizedLayout(gridType: number, leafSize: number): GridTypeLayout {\n return {\n ...FLOAT_LAYOUT,\n gridType,\n valueStrideBits: 0, // not a uniform stride for quantized leaves\n leafSize,\n leafOffTable: LEAF_OFF_FP_CODES,\n leafOffMin: LEAF_OFF_FP_STAT_MIN,\n leafOffMax: LEAF_OFF_FP_STAT_MAX,\n leafOffAve: LEAF_OFF_FP_STAT_AVG,\n leafOffStdDev: LEAF_OFF_FP_STAT_DEV,\n };\n}\n\n/** Fp8: fixed 8-bit codes. Leaf = 96-byte header + 512 bytes = 608. */\nexport const FP8_LAYOUT: GridTypeLayout = quantizedLayout(GRID_TYPE_FP8, 608);\n/** Fp4: fixed 4-bit codes. Leaf = 96-byte header + 256 bytes = 352. */\nexport const FP4_LAYOUT: GridTypeLayout = quantizedLayout(GRID_TYPE_FP4, 352);\n/** Fp16: fixed 16-bit codes. Leaf = 96-byte header + 1024 bytes = 1120. */\nexport const FP16_LAYOUT: GridTypeLayout = quantizedLayout(GRID_TYPE_FP16, 1120);\n/** FpN: variable bit-width. `leafSize` is the 96-byte base (see codec). */\nexport const FPN_LAYOUT: GridTypeLayout = quantizedLayout(GRID_TYPE_FPN, FP_LEAF_HEADER_SIZE);\n\n/**\n * Half (K7.H, NanoVDB `GridType::Half`): every value is a raw IEEE binary16\n * (2 bytes) at every level (leaf table, tiles, background); `mMinimum` /\n * `mMaximum` are binary16 too and `mAverage` / `mStdDevi` stay f32\n * (`FloatTraits<Half>` is float). Table slots stay 8 bytes (the value in the\n * low 2 bytes of the union with the i64 child offset); the leaf table is at 96\n * (512 x 2 bytes, leaf 1120). Values from `PNANOVDB_GRID_TYPE_HALF` in the\n * vendored stride tables (unchanged in NanoVDB v14.0.0's PNanoVDB.h).\n */\nexport const HALF_LAYOUT: GridTypeLayout = {\n gridType: GRID_TYPE_HALF,\n rootSize: 64,\n rootTileSize: 32,\n rootTileOffValue: 20,\n rootOffBackground: 28,\n rootOffMin: 30,\n rootOffMax: 32,\n rootOffAve: 36,\n rootOffStdDev: 40,\n tableStride: 8,\n valueStrideBits: 16,\n upperSize: 270400,\n upperOffTable: 8256,\n upperOffMin: 8224,\n upperOffMax: 8226,\n upperOffAve: 8228,\n upperOffStdDev: 8232,\n lowerSize: 33856,\n lowerOffTable: 1088,\n lowerOffMin: 1056,\n lowerOffMax: 1058,\n lowerOffAve: 1060,\n lowerOffStdDev: 1064,\n leafSize: 1120,\n leafOffTable: 96,\n leafOffMin: 80,\n leafOffMax: 82,\n leafOffAve: 84,\n leafOffStdDev: 88,\n};\n\n/**\n * Vec3f (K4.2): every value is 3 f32 (12 bytes); `mMinimum`/`mMaximum` are\n * Vec3f and `mAverage`/`mStdDevi` stay f32 (`FloatTraits<Vec3f>` is float).\n * Internal-node table slots are 16 bytes (the union of a 12-byte value and an\n * i64 child offset); the leaf table is 32-byte aligned at 128. Values from\n * `PNANOVDB_GRID_TYPE_VEC3F` in the vendored stride tables.\n */\nexport const VEC3F_LAYOUT: GridTypeLayout = {\n gridType: GRID_TYPE_VEC3F,\n rootSize: 96,\n rootTileSize: 32,\n rootTileOffValue: 20,\n rootOffBackground: 28,\n rootOffMin: 40,\n rootOffMax: 52,\n rootOffAve: 64,\n rootOffStdDev: 68,\n tableStride: 16,\n valueStrideBits: 96,\n upperSize: 532544,\n upperOffTable: 8256,\n upperOffMin: 8224,\n upperOffMax: 8236,\n upperOffAve: 8248,\n upperOffStdDev: 8252,\n lowerSize: 66624,\n lowerOffTable: 1088,\n lowerOffMin: 1056,\n lowerOffMax: 1068,\n lowerOffAve: 1080,\n lowerOffStdDev: 1084,\n leafSize: 6272,\n leafOffTable: 128,\n leafOffMin: 80,\n leafOffMax: 92,\n leafOffAve: 104,\n leafOffStdDev: 108,\n};\n\n// ---------------------------------------------------------------------------\n// coord -> key / coord -> offset (structural bit math, identical for all types)\n// ---------------------------------------------------------------------------\n\n/** pnanovdb_coord_to_key — root-tile key for a voxel coord (native-64 branch). */\nexport function coordToKey(x: number, y: number, z: number): bigint {\n const iu = BigInt(x >>> 12);\n const ju = BigInt(y >>> 12);\n const ku = BigInt(z >>> 12);\n return ku | (ju << 21n) | (iu << 42n);\n}\n\n/** pnanovdb_upper_coord_to_offset — lower-table slot within a 32^3 upper. */\nexport function upperCoordToOffset(x: number, y: number, z: number): number {\n return (((x & 4095) >> 7) << 10) + (((y & 4095) >> 7) << 5) + ((z & 4095) >> 7);\n}\n\n/** pnanovdb_lower_coord_to_offset — leaf-table slot within a 16^3 lower. */\nexport function lowerCoordToOffset(x: number, y: number, z: number): number {\n return (((x & 127) >> 3) << 8) + (((y & 127) >> 3) << 4) + ((z & 127) >> 3);\n}\n\n/** pnanovdb_leaf_coord_to_offset — voxel slot within an 8^3 leaf, 0..511. */\nexport function leafCoordToOffset(x: number, y: number, z: number): number {\n return ((x & 7) << 6) + ((y & 7) << 3) + (z & 7);\n}\n\n// ---------------------------------------------------------------------------\n// GridImageWriter — typed little-endian struct writer over one grid image.\n// ---------------------------------------------------------------------------\n\n/**\n * A thin, endianness-explicit writer over a single grid image's backing\n * `ArrayBuffer`. All NanoVDB integers/floats are little-endian; every setter\n * here passes `true` so the code never repeats the flag. Mask helpers implement\n * `pnanovdb_*_mask` bit addressing (32-bit words, LSB-first within a word).\n */\nexport class GridImageWriter {\n readonly bytes: Uint8Array;\n readonly u32: Uint32Array;\n private readonly view: DataView;\n\n constructor(byteLength: number) {\n if (byteLength % 4 !== 0) {\n throw new Error(`GridImageWriter: byteLength ${byteLength} must be a multiple of 4`);\n }\n const buffer = new ArrayBuffer(byteLength);\n this.bytes = new Uint8Array(buffer);\n this.u32 = new Uint32Array(buffer);\n this.view = new DataView(buffer);\n }\n\n setU16(off: number, v: number): void {\n this.view.setUint16(off, v & 0xffff, true);\n }\n setU32(off: number, v: number): void {\n this.view.setUint32(off, v >>> 0, true);\n }\n setI32(off: number, v: number): void {\n this.view.setInt32(off, v | 0, true);\n }\n setU64(off: number, v: bigint): void {\n this.view.setBigUint64(off, v, true);\n }\n setI64(off: number, v: bigint): void {\n this.view.setBigInt64(off, v, true);\n }\n setF32(off: number, v: number): void {\n this.view.setFloat32(off, v, true);\n }\n setF64(off: number, v: number): void {\n this.view.setFloat64(off, v, true);\n }\n\n /** Writes `len` bytes of `src` at `off`, zero-filling nothing beyond it. */\n setBytes(off: number, src: Uint8Array): void {\n this.bytes.set(src, off);\n }\n\n /** Sets bit `bitIndex` of a mask word array whose word 0 starts at `maskBase`. */\n setMaskBit(maskBase: number, bitIndex: number): void {\n const wordOff = maskBase + 4 * (bitIndex >>> 5);\n this.view.setUint32(\n wordOff,\n (this.view.getUint32(wordOff, true) | (1 << (bitIndex & 31))) >>> 0,\n true,\n );\n }\n\n /** Copies a whole precomputed 32-bit mask (`words` u32s) to `maskBase`. */\n setMaskWords(maskBase: number, words: Uint32Array): void {\n for (let i = 0; i < words.length; i++) {\n this.view.setUint32(maskBase + i * 4, words[i]! >>> 0, true);\n }\n }\n}\n"]}
@@ -0,0 +1,78 @@
1
+ /**
2
+ * coarse-first.ts — `vdbBakeCoarseFirst` (K4.16): the K4.5 option (a) bake. A
3
+ * small preview grid (or a chain, coarsest first) and then the full grid, in
4
+ * one multi-grid `.nvdb` (docs/dev/design/K4-5-coarse-first.md):
5
+ *
6
+ * [ <name>.lod48 , <name> ]
7
+ *
8
+ * Previews are `vdbResampleGrid(source, { resolution, filter, quantize })` over
9
+ * the source's active cell box, so they draw where the full grid draws.
10
+ * Readers tell them apart by name: a preview is `<name>.lod<resolution>`
11
+ * (`parseNvdbLodName`), the full grid keeps the source name, so a native
12
+ * reader that selects by name (`io::readGrid(file, "density")`) gets the
13
+ * full grid. A reader that takes grid 0 gets the coarsest preview (K4.17).
14
+ * `segments: 'per-grid'` writes one segment per grid, so native index reads
15
+ * (`io::readGrid(file, n)`) work too (K7.12).
16
+ */
17
+ import type { VdbFile, VdbGrid } from "../vdb/types.js";
18
+ import { type VDBQuantizeMode } from "./quantize.js";
19
+ import { type VDBResampleFilter } from "./resample.js";
20
+ /** Options of {@link vdbBakeCoarseFirst}. */
21
+ export interface VDBBakeCoarseFirstOptions {
22
+ /**
23
+ * Preview resolution(s): voxels on the longest side of the source's active
24
+ * box (`vdbResampleGrid`'s `resolution`). Several give a chain, written
25
+ * coarsest first. Default 48 (the K4.5 recommendation).
26
+ */
27
+ previewResolution?: number | number[];
28
+ /**
29
+ * Preview filter. Default `'trilinear'` (D26: ~1 dB closer to the full render than `'box'` at resolution 48
30
+ * in the K4.19 A/B). Use `'box'` for thin or high-frequency data (most phase-stable, conserves mass).
31
+ */
32
+ filter?: VDBResampleFilter;
33
+ /** Preview encoding. Default `'fpn'`. */
34
+ quantize?: VDBQuantizeMode | "none";
35
+ /** FpN tolerance for the previews (and a quantized full grid). Default `quantize`'s (0.01). */
36
+ tolerance?: number;
37
+ /**
38
+ * Full-grid encoding. Default: the image as given for a NanoVDB source, and
39
+ * `quantize`'s value for a parsed `.vdb` source (built with `buildFromVdb`
40
+ * first). Quantizing needs a FLOAT image.
41
+ */
42
+ fullQuantize?: VDBQuantizeMode | "none";
43
+ /**
44
+ * Per-grid codec. Default `'zip'` (K4.18): the preview is ~12 KiB inside the
45
+ * file whatever the host does; `'none'` relies on HTTP compression (a raw
46
+ * preview is ~300 KiB, the 270 KB upper node); `'blosc'` (K7.C1) writes
47
+ * NanoVDB's LZ4 Blosc frames (larger than ZIP, faster to decode natively).
48
+ */
49
+ codec?: "none" | "zip" | "blosc";
50
+ /** zlib level for `codec: 'zip'`. Default 9. */
51
+ zipLevel?: number;
52
+ /**
53
+ * Segment layout (K7.12, `writeNvdb`'s `segments`). `'one'` (default): every grid in one segment, so a stream
54
+ * reader knows the full grid's size, type and voxel size before the preview's data (`vdbStreamCoarseFirst`
55
+ * reserves the full size at the preview: no pool growth at the swap). `'per-grid'`: one segment per grid, so
56
+ * native `io::readGrid(file, n)` reads every grid (v14 misreads n >= 1 inside a multi-grid segment, K7.13); a
57
+ * stream then learns of the full grid only when its segment starts (the swap moves the grid to a larger range,
58
+ * and the preview's `voxelRatio` / `types` cover only the grids announced so far).
59
+ */
60
+ segments?: "one" | "per-grid";
61
+ /** Which float grid of a `VdbFile` to bake. Default: the first float grid. */
62
+ sourceGridName?: string;
63
+ /**
64
+ * Collapse uniform regions into tiles (K4.6). Default: on for the previews
65
+ * (`vdbResampleGrid`'s default) and off for the full grid (an image keeps its
66
+ * topology; a `.vdb` grid is built as `nanovdb_convert` builds it). A value
67
+ * given applies to every grid.
68
+ */
69
+ collapse?: boolean;
70
+ }
71
+ /**
72
+ * Bakes a coarse-first `.nvdb`: previews at `previewResolution` (coarsest
73
+ * first), then the full grid, in one segment (or one per grid), as file bytes.
74
+ *
75
+ * @param source The full grid: a NanoVDB image, a parsed `.vdb` grid, or a parsed `.vdb` file (its first float grid).
76
+ * @param options Preview resolution(s), filter, quantization, tolerance, codec and segment layout.
77
+ */
78
+ export declare function vdbBakeCoarseFirst(source: Uint32Array | VdbGrid | VdbFile, options?: VDBBakeCoarseFirstOptions): Uint8Array;
@@ -0,0 +1,92 @@
1
+ /**
2
+ * coarse-first.ts — `vdbBakeCoarseFirst` (K4.16): the K4.5 option (a) bake. A
3
+ * small preview grid (or a chain, coarsest first) and then the full grid, in
4
+ * one multi-grid `.nvdb` (docs/dev/design/K4-5-coarse-first.md):
5
+ *
6
+ * [ <name>.lod48 , <name> ]
7
+ *
8
+ * Previews are `vdbResampleGrid(source, { resolution, filter, quantize })` over
9
+ * the source's active cell box, so they draw where the full grid draws.
10
+ * Readers tell them apart by name: a preview is `<name>.lod<resolution>`
11
+ * (`parseNvdbLodName`), the full grid keeps the source name, so a native
12
+ * reader that selects by name (`io::readGrid(file, "density")`) gets the
13
+ * full grid. A reader that takes grid 0 gets the coarsest preview (K4.17).
14
+ * `segments: 'per-grid'` writes one segment per grid, so native index reads
15
+ * (`io::readGrid(file, n)`) work too (K7.12).
16
+ */
17
+ import { VDBToolsError } from "../errors.js";
18
+ import { nvdbLodName } from "../nvdb-stream.js";
19
+ import { GRID_NAME_MAX, GRID_OFF_GRID_NAME } from "./bytes.js";
20
+ import { buildFromVdb } from "./build-from-vdb.js";
21
+ import { vdbCollapseGrid, vdbQuantize } from "./quantize.js";
22
+ import { vdbResampleGrid } from "./resample.js";
23
+ import { writeNvdb } from "./write-nvdb.js";
24
+ function imageName(image) {
25
+ const bytes = new Uint8Array(image.buffer, image.byteOffset + GRID_OFF_GRID_NAME, GRID_NAME_MAX);
26
+ const end = bytes.indexOf(0);
27
+ return new TextDecoder().decode(bytes.subarray(0, end < 0 ? bytes.length : end));
28
+ }
29
+ function pickGrid(file, name) {
30
+ const grid = file.grids.find((g) => g.valueType === "float" && (name === undefined || g.name === name));
31
+ if (!grid) {
32
+ throw new VDBToolsError("VDB_BAD_OPTION", `vdbBakeCoarseFirst: no float grid${name === undefined ? "" : ` named "${name}"`} in the file ` +
33
+ `(grids: ${file.grids.map((g) => `${g.name}:${g.valueType}`).join(", ") || "none"})`);
34
+ }
35
+ return grid;
36
+ }
37
+ /**
38
+ * Bakes a coarse-first `.nvdb`: previews at `previewResolution` (coarsest
39
+ * first), then the full grid, in one segment (or one per grid), as file bytes.
40
+ *
41
+ * @param source The full grid: a NanoVDB image, a parsed `.vdb` grid, or a parsed `.vdb` file (its first float grid).
42
+ * @param options Preview resolution(s), filter, quantization, tolerance, codec and segment layout.
43
+ */
44
+ export function vdbBakeCoarseFirst(source, options = {}) {
45
+ const resolutions = [options.previewResolution ?? 48].flat();
46
+ if (resolutions.length === 0)
47
+ throw new VDBToolsError("VDB_BAD_OPTION", "vdbBakeCoarseFirst: previewResolution is empty");
48
+ for (const r of resolutions) {
49
+ if (!Number.isInteger(r) || r < 1)
50
+ throw new VDBToolsError("VDB_BAD_OPTION", `vdbBakeCoarseFirst: previewResolution must be positive integers, got ${r}`);
51
+ }
52
+ if (new Set(resolutions).size !== resolutions.length)
53
+ throw new VDBToolsError("VDB_BAD_OPTION", "vdbBakeCoarseFirst: previewResolution has duplicates");
54
+ resolutions.sort((a, b) => a - b);
55
+ const previewQuantize = options.quantize ?? "fpn";
56
+ // The full grid.
57
+ let full;
58
+ let resampleSource;
59
+ if (source instanceof Uint32Array) {
60
+ full = source;
61
+ resampleSource = source;
62
+ const q = options.fullQuantize ?? "none";
63
+ if (q !== "none")
64
+ full = vdbQuantize(source, q, options.tolerance, { collapse: options.collapse === true });
65
+ else if (options.collapse === true)
66
+ full = vdbCollapseGrid(source).image;
67
+ }
68
+ else {
69
+ const grid = "grids" in source ? pickGrid(source, options.sourceGridName) : source;
70
+ resampleSource = grid;
71
+ full = buildFromVdb(grid, { collapse: options.collapse === true });
72
+ const q = options.fullQuantize ?? previewQuantize;
73
+ if (q !== "none")
74
+ full = vdbQuantize(full, q, options.tolerance);
75
+ }
76
+ const name = imageName(full);
77
+ const previews = resolutions.map((resolution) => vdbResampleGrid(resampleSource, {
78
+ resolution,
79
+ filter: options.filter ?? "trilinear",
80
+ ...(previewQuantize === "none" ? {} : { quantize: previewQuantize }),
81
+ ...(options.tolerance === undefined ? {} : { tolerance: options.tolerance }),
82
+ gridName: nvdbLodName(name, resolution),
83
+ ...(options.collapse === undefined ? {} : { collapse: options.collapse }),
84
+ }).image);
85
+ const file = writeNvdb([...previews, full], {
86
+ codec: options.codec ?? "zip",
87
+ ...(options.zipLevel === undefined ? {} : { zipLevel: options.zipLevel }),
88
+ ...(options.segments === undefined ? {} : { segments: options.segments }),
89
+ });
90
+ return new Uint8Array(file);
91
+ }
92
+ //# sourceMappingURL=coarse-first.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coarse-first.js","sourceRoot":"","sources":["../../../src/tools/nanovdb/coarse-first.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO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AO,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC;KAC1E,CAAC,CAAC,KAAK,CACX,CAAC;IAEF,MAAM,IAAI,GAAG,SAAS,CAAC,CAAC,GAAG,QAAQ,EAAE,IAAI,CAAC,EAAE;QAC1C,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,KAAK;QAC7B,GAAG,CAAC,OAAO,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC;QACzE,GAAG,CAAC,OAAO,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC;KAC1E,CAAC,CAAC;IACH,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["/**\n * coarse-first.ts — `vdbBakeCoarseFirst` (K4.16): the K4.5 option (a) bake. A\n * small preview grid (or a chain, coarsest first) and then the full grid, in\n * one multi-grid `.nvdb` (docs/dev/design/K4-5-coarse-first.md):\n *\n * [ <name>.lod48 , <name> ]\n *\n * Previews are `vdbResampleGrid(source, { resolution, filter, quantize })` over\n * the source's active cell box, so they draw where the full grid draws.\n * Readers tell them apart by name: a preview is `<name>.lod<resolution>`\n * (`parseNvdbLodName`), the full grid keeps the source name, so a native\n * reader that selects by name (`io::readGrid(file, \"density\")`) gets the\n * full grid. A reader that takes grid 0 gets the coarsest preview (K4.17).\n * `segments: 'per-grid'` writes one segment per grid, so native index reads\n * (`io::readGrid(file, n)`) work too (K7.12).\n */\n\nimport { VDBToolsError } from \"../errors.js\";\nimport { nvdbLodName } from \"../nvdb-stream.js\";\nimport type { VdbFile, VdbGrid } from \"../vdb/types.js\";\nimport { GRID_NAME_MAX, GRID_OFF_GRID_NAME } from \"./bytes.js\";\nimport { buildFromVdb } from \"./build-from-vdb.js\";\nimport { vdbCollapseGrid, vdbQuantize, type VDBQuantizeMode } from \"./quantize.js\";\nimport { vdbResampleGrid, type VDBResampleFilter } from \"./resample.js\";\nimport { writeNvdb } from \"./write-nvdb.js\";\n\n/** Options of {@link vdbBakeCoarseFirst}. */\nexport interface VDBBakeCoarseFirstOptions {\n /**\n * Preview resolution(s): voxels on the longest side of the source's active\n * box (`vdbResampleGrid`'s `resolution`). Several give a chain, written\n * coarsest first. Default 48 (the K4.5 recommendation).\n */\n previewResolution?: number | number[];\n /**\n * Preview filter. Default `'trilinear'` (D26: ~1 dB closer to the full render than `'box'` at resolution 48\n * in the K4.19 A/B). Use `'box'` for thin or high-frequency data (most phase-stable, conserves mass).\n */\n filter?: VDBResampleFilter;\n /** Preview encoding. Default `'fpn'`. */\n quantize?: VDBQuantizeMode | \"none\";\n /** FpN tolerance for the previews (and a quantized full grid). Default `quantize`'s (0.01). */\n tolerance?: number;\n /**\n * Full-grid encoding. Default: the image as given for a NanoVDB source, and\n * `quantize`'s value for a parsed `.vdb` source (built with `buildFromVdb`\n * first). Quantizing needs a FLOAT image.\n */\n fullQuantize?: VDBQuantizeMode | \"none\";\n /**\n * Per-grid codec. Default `'zip'` (K4.18): the preview is ~12 KiB inside the\n * file whatever the host does; `'none'` relies on HTTP compression (a raw\n * preview is ~300 KiB, the 270 KB upper node); `'blosc'` (K7.C1) writes\n * NanoVDB's LZ4 Blosc frames (larger than ZIP, faster to decode natively).\n */\n codec?: \"none\" | \"zip\" | \"blosc\";\n /** zlib level for `codec: 'zip'`. Default 9. */\n zipLevel?: number;\n /**\n * Segment layout (K7.12, `writeNvdb`'s `segments`). `'one'` (default): every grid in one segment, so a stream\n * reader knows the full grid's size, type and voxel size before the preview's data (`vdbStreamCoarseFirst`\n * reserves the full size at the preview: no pool growth at the swap). `'per-grid'`: one segment per grid, so\n * native `io::readGrid(file, n)` reads every grid (v14 misreads n >= 1 inside a multi-grid segment, K7.13); a\n * stream then learns of the full grid only when its segment starts (the swap moves the grid to a larger range,\n * and the preview's `voxelRatio` / `types` cover only the grids announced so far).\n */\n segments?: \"one\" | \"per-grid\";\n /** Which float grid of a `VdbFile` to bake. Default: the first float grid. */\n sourceGridName?: string;\n /**\n * Collapse uniform regions into tiles (K4.6). Default: on for the previews\n * (`vdbResampleGrid`'s default) and off for the full grid (an image keeps its\n * topology; a `.vdb` grid is built as `nanovdb_convert` builds it). A value\n * given applies to every grid.\n */\n collapse?: boolean;\n}\n\nfunction imageName(image: Uint32Array): string {\n const bytes = new Uint8Array(image.buffer, image.byteOffset + GRID_OFF_GRID_NAME, GRID_NAME_MAX);\n const end = bytes.indexOf(0);\n return new TextDecoder().decode(bytes.subarray(0, end < 0 ? bytes.length : end));\n}\n\nfunction pickGrid(file: VdbFile, name: string | undefined): VdbGrid {\n const grid = file.grids.find((g) => g.valueType === \"float\" && (name === undefined || g.name === name));\n if (!grid) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", \n `vdbBakeCoarseFirst: no float grid${name === undefined ? \"\" : ` named \"${name}\"`} in the file ` +\n `(grids: ${file.grids.map((g) => `${g.name}:${g.valueType}`).join(\", \") || \"none\"})`,\n );\n }\n return grid;\n}\n\n/**\n * Bakes a coarse-first `.nvdb`: previews at `previewResolution` (coarsest\n * first), then the full grid, in one segment (or one per grid), as file bytes.\n *\n * @param source The full grid: a NanoVDB image, a parsed `.vdb` grid, or a parsed `.vdb` file (its first float grid).\n * @param options Preview resolution(s), filter, quantization, tolerance, codec and segment layout.\n */\nexport function vdbBakeCoarseFirst(source: Uint32Array | VdbGrid | VdbFile, options: VDBBakeCoarseFirstOptions = {}): Uint8Array {\n const resolutions = [options.previewResolution ?? 48].flat();\n if (resolutions.length === 0) throw new VDBToolsError(\"VDB_BAD_OPTION\", \"vdbBakeCoarseFirst: previewResolution is empty\");\n for (const r of resolutions) {\n if (!Number.isInteger(r) || r < 1) throw new VDBToolsError(\"VDB_BAD_OPTION\", `vdbBakeCoarseFirst: previewResolution must be positive integers, got ${r}`);\n }\n if (new Set(resolutions).size !== resolutions.length) throw new VDBToolsError(\"VDB_BAD_OPTION\", \"vdbBakeCoarseFirst: previewResolution has duplicates\");\n resolutions.sort((a, b) => a - b);\n const previewQuantize = options.quantize ?? \"fpn\";\n\n // The full grid.\n let full: Uint32Array;\n let resampleSource: Uint32Array | VdbGrid;\n if (source instanceof Uint32Array) {\n full = source;\n resampleSource = source;\n const q = options.fullQuantize ?? \"none\";\n if (q !== \"none\") full = vdbQuantize(source, q, options.tolerance, { collapse: options.collapse === true });\n else if (options.collapse === true) full = vdbCollapseGrid(source).image;\n } else {\n const grid = \"grids\" in source ? pickGrid(source, options.sourceGridName) : source;\n resampleSource = grid;\n full = buildFromVdb(grid, { collapse: options.collapse === true });\n const q = options.fullQuantize ?? previewQuantize;\n if (q !== \"none\") full = vdbQuantize(full, q, options.tolerance);\n }\n const name = imageName(full);\n\n const previews = resolutions.map(\n (resolution) =>\n vdbResampleGrid(resampleSource, {\n resolution,\n filter: options.filter ?? \"trilinear\",\n ...(previewQuantize === \"none\" ? {} : { quantize: previewQuantize }),\n ...(options.tolerance === undefined ? {} : { tolerance: options.tolerance }),\n gridName: nvdbLodName(name, resolution),\n ...(options.collapse === undefined ? {} : { collapse: options.collapse }),\n }).image,\n );\n\n const file = writeNvdb([...previews, full], {\n codec: options.codec ?? \"zip\",\n ...(options.zipLevel === undefined ? {} : { zipLevel: options.zipLevel }),\n ...(options.segments === undefined ? {} : { segments: options.segments }),\n });\n return new Uint8Array(file);\n}\n"]}