@pmndrs/vdb 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (576) hide show
  1. package/CHANGELOG.md +592 -2
  2. package/README.md +85 -37
  3. package/THIRD_PARTY_NOTICES.md +197 -29
  4. package/dist/core/compute/atlas.d.ts +10 -2
  5. package/dist/core/compute/atlas.js +6 -1
  6. package/dist/core/compute/atlas.js.map +1 -1
  7. package/dist/core/compute/index.d.ts +3 -3
  8. package/dist/core/compute/index.js +2 -2
  9. package/dist/core/compute/index.js.map +1 -1
  10. package/dist/core/compute/majorant-build.d.ts +45 -0
  11. package/dist/core/compute/majorant-build.js +193 -0
  12. package/dist/core/compute/majorant-build.js.map +1 -0
  13. package/dist/core/compute/multi-scale.d.ts +155 -0
  14. package/dist/core/compute/multi-scale.js +684 -0
  15. package/dist/core/compute/multi-scale.js.map +1 -0
  16. package/dist/core/compute/pyramid.d.ts +22 -7
  17. package/dist/core/compute/pyramid.js +22 -9
  18. package/dist/core/compute/pyramid.js.map +1 -1
  19. package/dist/core/compute/shared.d.ts +1 -0
  20. package/dist/core/compute/shared.js.map +1 -1
  21. package/dist/core/compute/stats.d.ts +10 -3
  22. package/dist/core/compute/stats.js +6 -1
  23. package/dist/core/compute/stats.js.map +1 -1
  24. package/dist/core/compute/value-transform.d.ts +8 -1
  25. package/dist/core/compute/value-transform.js +9 -3
  26. package/dist/core/compute/value-transform.js.map +1 -1
  27. package/dist/core/errors.d.ts +10 -0
  28. package/dist/core/errors.js +8 -0
  29. package/dist/core/errors.js.map +1 -1
  30. package/dist/core/frame/emission.d.ts +85 -0
  31. package/dist/core/frame/emission.js +422 -0
  32. package/dist/core/frame/emission.js.map +1 -0
  33. package/dist/core/frame/environment.d.ts +47 -0
  34. package/dist/core/frame/environment.js +178 -0
  35. package/dist/core/frame/environment.js.map +1 -0
  36. package/dist/core/frame/index.d.ts +39 -0
  37. package/dist/core/frame/index.js +27 -0
  38. package/dist/core/frame/index.js.map +1 -0
  39. package/dist/core/frame/kernels.d.ts +115 -0
  40. package/dist/core/frame/kernels.js +496 -0
  41. package/dist/core/frame/kernels.js.map +1 -0
  42. package/dist/core/frame/limits.d.ts +67 -0
  43. package/dist/core/frame/limits.js +109 -0
  44. package/dist/core/frame/limits.js.map +1 -0
  45. package/dist/core/frame/phase.d.ts +17 -0
  46. package/dist/core/frame/phase.js +53 -0
  47. package/dist/core/frame/phase.js.map +1 -0
  48. package/dist/core/frame/pipelines.d.ts +49 -0
  49. package/dist/core/frame/pipelines.js +147 -0
  50. package/dist/core/frame/pipelines.js.map +1 -0
  51. package/dist/core/frame/renderer.d.ts +122 -0
  52. package/dist/core/frame/renderer.js +1712 -0
  53. package/dist/core/frame/renderer.js.map +1 -0
  54. package/dist/core/frame/resources.d.ts +71 -0
  55. package/dist/core/frame/resources.js +100 -0
  56. package/dist/core/frame/resources.js.map +1 -0
  57. package/dist/core/frame/scattering.d.ts +97 -0
  58. package/dist/core/frame/scattering.js +332 -0
  59. package/dist/core/frame/scattering.js.map +1 -0
  60. package/dist/core/frame/settings.d.ts +243 -0
  61. package/dist/core/frame/settings.js +67 -0
  62. package/dist/core/frame/settings.js.map +1 -0
  63. package/dist/core/frame/shadows.d.ts +55 -0
  64. package/dist/core/frame/shadows.js +460 -0
  65. package/dist/core/frame/shadows.js.map +1 -0
  66. package/dist/core/frame/types.d.ts +415 -0
  67. package/dist/core/frame/types.js +49 -0
  68. package/dist/core/frame/types.js.map +1 -0
  69. package/dist/core/frame/uniforms.d.ts +105 -0
  70. package/dist/core/frame/uniforms.js +276 -0
  71. package/dist/core/frame/uniforms.js.map +1 -0
  72. package/dist/core/frame/wgsl/chunks.d.ts +4 -0
  73. package/dist/core/frame/wgsl/chunks.js +728 -0
  74. package/dist/core/frame/wgsl/chunks.js.map +1 -0
  75. package/dist/core/frame/wgsl/emission.d.ts +82 -0
  76. package/dist/core/frame/wgsl/emission.js +353 -0
  77. package/dist/core/frame/wgsl/emission.js.map +1 -0
  78. package/dist/core/frame/wgsl/environment.d.ts +42 -0
  79. package/dist/core/frame/wgsl/environment.js +711 -0
  80. package/dist/core/frame/wgsl/environment.js.map +1 -0
  81. package/dist/core/frame/wgsl/gather.d.ts +55 -0
  82. package/dist/core/frame/wgsl/gather.js +850 -0
  83. package/dist/core/frame/wgsl/gather.js.map +1 -0
  84. package/dist/core/frame/wgsl/integrate.d.ts +78 -0
  85. package/dist/core/frame/wgsl/integrate.js +213 -0
  86. package/dist/core/frame/wgsl/integrate.js.map +1 -0
  87. package/dist/core/frame/wgsl/lighting.d.ts +103 -0
  88. package/dist/core/frame/wgsl/lighting.js +1636 -0
  89. package/dist/core/frame/wgsl/lighting.js.map +1 -0
  90. package/dist/core/frame/wgsl/occluders.d.ts +20 -0
  91. package/dist/core/frame/wgsl/occluders.js +95 -0
  92. package/dist/core/frame/wgsl/occluders.js.map +1 -0
  93. package/dist/core/frame/wgsl/resolve.d.ts +19 -0
  94. package/dist/core/frame/wgsl/resolve.js +205 -0
  95. package/dist/core/frame/wgsl/resolve.js.map +1 -0
  96. package/dist/core/frame/wgsl/shadows.d.ts +35 -0
  97. package/dist/core/frame/wgsl/shadows.js +328 -0
  98. package/dist/core/frame/wgsl/shadows.js.map +1 -0
  99. package/dist/core/half.d.ts +11 -0
  100. package/dist/core/half.js +22 -0
  101. package/dist/core/half.js.map +1 -0
  102. package/dist/core/index.d.ts +25 -3
  103. package/dist/core/index.js +23 -4
  104. package/dist/core/index.js.map +1 -1
  105. package/dist/core/internal.d.ts +17 -1
  106. package/dist/core/internal.js +18 -1
  107. package/dist/core/internal.js.map +1 -1
  108. package/dist/core/pool/image-header.d.ts +13 -2
  109. package/dist/core/pool/image-header.js +24 -5
  110. package/dist/core/pool/image-header.js.map +1 -1
  111. package/dist/core/pool/layout.d.ts +35 -1
  112. package/dist/core/pool/layout.js +51 -2
  113. package/dist/core/pool/layout.js.map +1 -1
  114. package/dist/core/pool/limits.d.ts +1 -0
  115. package/dist/core/pool/limits.js +1 -0
  116. package/dist/core/pool/limits.js.map +1 -1
  117. package/dist/core/pool/pool.d.ts +120 -15
  118. package/dist/core/pool/pool.js +255 -24
  119. package/dist/core/pool/pool.js.map +1 -1
  120. package/dist/core/reference/index.d.ts +6 -0
  121. package/dist/core/reference/index.js +7 -0
  122. package/dist/core/reference/index.js.map +1 -0
  123. package/dist/core/reference/renderer.d.ts +105 -0
  124. package/dist/core/reference/renderer.js +474 -0
  125. package/dist/core/reference/renderer.js.map +1 -0
  126. package/dist/core/reference/wgsl.d.ts +65 -0
  127. package/dist/core/reference/wgsl.js +803 -0
  128. package/dist/core/reference/wgsl.js.map +1 -0
  129. package/dist/{three → core}/sequence.d.ts +32 -2
  130. package/dist/{three → core}/sequence.js +24 -2
  131. package/dist/core/sequence.js.map +1 -0
  132. package/dist/core/source/brick-cache.d.ts +165 -0
  133. package/dist/core/source/brick-cache.js +627 -0
  134. package/dist/core/source/brick-cache.js.map +1 -0
  135. package/dist/core/source/dense-fill.d.ts +53 -0
  136. package/dist/core/source/dense-fill.js +377 -0
  137. package/dist/core/source/dense-fill.js.map +1 -0
  138. package/dist/core/source/dense.d.ts +33 -2
  139. package/dist/core/source/dense.js +121 -24
  140. package/dist/core/source/dense.js.map +1 -1
  141. package/dist/core/source/sparse-wgsl.d.ts +92 -0
  142. package/dist/core/source/sparse-wgsl.js +481 -0
  143. package/dist/core/source/sparse-wgsl.js.map +1 -0
  144. package/dist/core/source/sparse.d.ts +192 -0
  145. package/dist/core/source/sparse.js +762 -0
  146. package/dist/core/source/sparse.js.map +1 -0
  147. package/dist/core/source/types.d.ts +59 -2
  148. package/dist/core/source/types.js.map +1 -1
  149. package/dist/core/surface/index.d.ts +10 -0
  150. package/dist/core/surface/index.js +9 -0
  151. package/dist/core/surface/index.js.map +1 -0
  152. package/dist/core/surface/level-set-pass.d.ts +140 -0
  153. package/dist/core/surface/level-set-pass.js +291 -0
  154. package/dist/core/surface/level-set-pass.js.map +1 -0
  155. package/dist/core/surface/level-set-wgsl.d.ts +46 -0
  156. package/dist/core/surface/level-set-wgsl.js +99 -0
  157. package/dist/core/surface/level-set-wgsl.js.map +1 -0
  158. package/dist/core/surface/points.d.ts +109 -0
  159. package/dist/core/surface/points.js +226 -0
  160. package/dist/core/surface/points.js.map +1 -0
  161. package/dist/core/types.d.ts +12 -3
  162. package/dist/core/types.js +6 -2
  163. package/dist/core/types.js.map +1 -1
  164. package/dist/core/wgsl/api.d.ts +29 -5
  165. package/dist/core/wgsl/api.js +110 -27
  166. package/dist/core/wgsl/api.js.map +1 -1
  167. package/dist/core/wgsl/generate.d.ts +8 -0
  168. package/dist/core/wgsl/generate.js +195 -22
  169. package/dist/core/wgsl/generate.js.map +1 -1
  170. package/dist/core/wgsl/lean.d.ts +50 -0
  171. package/dist/core/wgsl/lean.js +327 -0
  172. package/dist/core/wgsl/lean.js.map +1 -0
  173. package/dist/core/wgsl/level-set.d.ts +5 -1
  174. package/dist/core/wgsl/level-set.js +11 -5
  175. package/dist/core/wgsl/level-set.js.map +1 -1
  176. package/dist/core/wgsl/majorant.d.ts +62 -0
  177. package/dist/core/wgsl/majorant.js +381 -0
  178. package/dist/core/wgsl/majorant.js.map +1 -0
  179. package/dist/core/wgsl/pnanovdb.chunks.generated.d.ts +2 -2
  180. package/dist/core/wgsl/pnanovdb.chunks.generated.js +15 -12
  181. package/dist/core/wgsl/pnanovdb.chunks.generated.js.map +1 -1
  182. package/dist/core/wgsl/types.d.ts +97 -3
  183. package/dist/core/wgsl/types.js.map +1 -1
  184. package/dist/three/coarse-first.d.ts +53 -8
  185. package/dist/three/coarse-first.js +24 -6
  186. package/dist/three/coarse-first.js.map +1 -1
  187. package/dist/three/compute.d.ts +12 -2
  188. package/dist/three/compute.js +16 -6
  189. package/dist/three/compute.js.map +1 -1
  190. package/dist/three/device.d.ts +7 -0
  191. package/dist/three/device.js +3 -0
  192. package/dist/three/device.js.map +1 -1
  193. package/dist/three/frame/core-environment.d.ts +38 -0
  194. package/dist/three/frame/core-environment.js +154 -0
  195. package/dist/three/frame/core-environment.js.map +1 -0
  196. package/dist/three/frame/core-integrate-material.d.ts +34 -0
  197. package/dist/three/frame/core-integrate-material.js +162 -0
  198. package/dist/three/frame/core-integrate-material.js.map +1 -0
  199. package/dist/three/frame/core-occluders.d.ts +53 -0
  200. package/dist/three/frame/core-occluders.js +193 -0
  201. package/dist/three/frame/core-occluders.js.map +1 -0
  202. package/dist/three/frame/core-structs.d.ts +34 -0
  203. package/dist/three/frame/core-structs.js +61 -0
  204. package/dist/three/frame/core-structs.js.map +1 -0
  205. package/dist/three/frame/core-textures.d.ts +41 -0
  206. package/dist/three/frame/core-textures.js +114 -0
  207. package/dist/three/frame/core-textures.js.map +1 -0
  208. package/dist/three/frame/emission-light.d.ts +64 -114
  209. package/dist/three/frame/emission-light.js +188 -567
  210. package/dist/three/frame/emission-light.js.map +1 -1
  211. package/dist/three/frame/index.d.ts +11 -31
  212. package/dist/three/frame/index.js +9 -29
  213. package/dist/three/frame/index.js.map +1 -1
  214. package/dist/three/frame/medium.d.ts +12 -0
  215. package/dist/three/frame/medium.js.map +1 -1
  216. package/dist/three/frame/renderer.d.ts +58 -454
  217. package/dist/three/frame/renderer.js +409 -1427
  218. package/dist/three/frame/renderer.js.map +1 -1
  219. package/dist/three/frame/spectrum.d.ts +0 -14
  220. package/dist/three/frame/spectrum.js +2 -23
  221. package/dist/three/frame/spectrum.js.map +1 -1
  222. package/dist/three/frame/three-internals.d.ts +3 -8
  223. package/dist/three/frame/three-internals.js +13 -11
  224. package/dist/three/frame/three-internals.js.map +1 -1
  225. package/dist/three/frame/volume-shadows.d.ts +93 -107
  226. package/dist/three/frame/volume-shadows.js +278 -631
  227. package/dist/three/frame/volume-shadows.js.map +1 -1
  228. package/dist/three/frame/volume.d.ts +91 -33
  229. package/dist/three/frame/volume.js +63 -51
  230. package/dist/three/frame/volume.js.map +1 -1
  231. package/dist/three/grid-node.d.ts +34 -1
  232. package/dist/three/grid-node.js +36 -1
  233. package/dist/three/grid-node.js.map +1 -1
  234. package/dist/three/index.d.ts +20 -11
  235. package/dist/three/index.js +21 -12
  236. package/dist/three/index.js.map +1 -1
  237. package/dist/three/internal.d.ts +14 -8
  238. package/dist/three/internal.js +11 -7
  239. package/dist/three/internal.js.map +1 -1
  240. package/dist/three/level-set-material.d.ts +81 -8
  241. package/dist/three/level-set-material.js +162 -125
  242. package/dist/three/level-set-material.js.map +1 -1
  243. package/dist/three/level-set-physical-material.d.ts +154 -0
  244. package/dist/three/level-set-physical-material.js +253 -0
  245. package/dist/three/level-set-physical-material.js.map +1 -0
  246. package/dist/three/level-set-velocity.d.ts +94 -0
  247. package/dist/three/level-set-velocity.js +208 -0
  248. package/dist/three/level-set-velocity.js.map +1 -0
  249. package/dist/three/material.d.ts +141 -11
  250. package/dist/three/material.js +161 -18
  251. package/dist/three/material.js.map +1 -1
  252. package/dist/three/points.d.ts +60 -4
  253. package/dist/three/points.js +140 -9
  254. package/dist/three/points.js.map +1 -1
  255. package/dist/three/sparse-source.d.ts +49 -117
  256. package/dist/three/sparse-source.js +109 -580
  257. package/dist/three/sparse-source.js.map +1 -1
  258. package/dist/three/volume-source.d.ts +11 -156
  259. package/dist/three/volume-source.js +29 -272
  260. package/dist/three/volume-source.js.map +1 -1
  261. package/dist/tools/cpu/brick-atlas.d.ts +36 -0
  262. package/dist/tools/cpu/brick-atlas.js +129 -0
  263. package/dist/tools/cpu/brick-atlas.js.map +1 -0
  264. package/dist/tools/cpu/compute.d.ts +23 -4
  265. package/dist/tools/cpu/compute.js +35 -14
  266. package/dist/tools/cpu/compute.js.map +1 -1
  267. package/dist/tools/cpu/lean-reads.d.ts +81 -0
  268. package/dist/tools/cpu/lean-reads.js +262 -0
  269. package/dist/tools/cpu/lean-reads.js.map +1 -0
  270. package/dist/tools/cpu/level-set.d.ts +42 -3
  271. package/dist/tools/cpu/level-set.js +59 -7
  272. package/dist/tools/cpu/level-set.js.map +1 -1
  273. package/dist/tools/cpu/majorant.d.ts +265 -0
  274. package/dist/tools/cpu/majorant.js +541 -0
  275. package/dist/tools/cpu/majorant.js.map +1 -0
  276. package/dist/tools/cpu/march.d.ts +93 -2
  277. package/dist/tools/cpu/march.js +165 -14
  278. package/dist/tools/cpu/march.js.map +1 -1
  279. package/dist/tools/cpu/mesh-decimate.d.ts +124 -0
  280. package/dist/tools/cpu/mesh-decimate.js +1225 -0
  281. package/dist/tools/cpu/mesh-decimate.js.map +1 -0
  282. package/dist/tools/cpu/points.d.ts +29 -0
  283. package/dist/tools/cpu/points.js +38 -0
  284. package/dist/tools/cpu/points.js.map +1 -0
  285. package/dist/tools/cpu/read-value.d.ts +19 -6
  286. package/dist/tools/cpu/read-value.js +32 -17
  287. package/dist/tools/cpu/read-value.js.map +1 -1
  288. package/dist/tools/cpu/sample-trilinear.d.ts +17 -4
  289. package/dist/tools/cpu/sample-trilinear.js +19 -7
  290. package/dist/tools/cpu/sample-trilinear.js.map +1 -1
  291. package/dist/tools/cpu/stride-tables.d.ts +2 -2
  292. package/dist/tools/cpu/stride-tables.generated.d.ts +6 -5
  293. package/dist/tools/cpu/stride-tables.generated.js +7 -6
  294. package/dist/tools/cpu/stride-tables.generated.js.map +1 -1
  295. package/dist/tools/cpu/stride-tables.js +1 -1
  296. package/dist/tools/cpu/stride-tables.js.map +1 -1
  297. package/dist/tools/cpu/surface-nets.d.ts +90 -0
  298. package/dist/tools/cpu/surface-nets.js +597 -0
  299. package/dist/tools/cpu/surface-nets.js.map +1 -0
  300. package/dist/tools/errors.d.ts +9 -0
  301. package/dist/tools/errors.js +9 -0
  302. package/dist/tools/errors.js.map +1 -1
  303. package/dist/tools/frame/ambient.d.ts +98 -0
  304. package/dist/tools/frame/ambient.js +274 -0
  305. package/dist/tools/frame/ambient.js.map +1 -0
  306. package/dist/tools/frame/blackbody.d.ts +15 -0
  307. package/dist/tools/frame/blackbody.js +35 -0
  308. package/dist/tools/frame/blackbody.js.map +1 -1
  309. package/dist/tools/frame/brick-cache.d.ts +165 -0
  310. package/dist/tools/frame/brick-cache.js +326 -0
  311. package/dist/tools/frame/brick-cache.js.map +1 -0
  312. package/dist/tools/frame/emission.d.ts +9 -0
  313. package/dist/tools/frame/emission.js +9 -1
  314. package/dist/tools/frame/emission.js.map +1 -1
  315. package/dist/tools/frame/environment-gpu.d.ts +111 -0
  316. package/dist/tools/frame/environment-gpu.js +280 -0
  317. package/dist/tools/frame/environment-gpu.js.map +1 -0
  318. package/dist/tools/frame/environment.d.ts +3 -2
  319. package/dist/tools/frame/environment.js +8 -4
  320. package/dist/tools/frame/environment.js.map +1 -1
  321. package/dist/tools/frame/froxel.d.ts +58 -0
  322. package/dist/tools/frame/froxel.js +115 -0
  323. package/dist/tools/frame/froxel.js.map +1 -0
  324. package/dist/tools/frame/grid.d.ts +90 -0
  325. package/dist/tools/frame/grid.js +112 -13
  326. package/dist/tools/frame/grid.js.map +1 -1
  327. package/dist/tools/frame/index.d.ts +14 -0
  328. package/dist/tools/frame/index.js +45 -4
  329. package/dist/tools/frame/index.js.map +1 -1
  330. package/dist/tools/frame/medium.d.ts +16 -0
  331. package/dist/tools/frame/medium.js +3 -1
  332. package/dist/tools/frame/medium.js.map +1 -1
  333. package/dist/tools/frame/mie.d.ts +9 -0
  334. package/dist/tools/frame/mie.js +18 -0
  335. package/dist/tools/frame/mie.js.map +1 -1
  336. package/dist/tools/frame/mlp-nn.d.ts +36 -0
  337. package/dist/tools/frame/mlp-nn.js +159 -0
  338. package/dist/tools/frame/mlp-nn.js.map +1 -0
  339. package/dist/tools/frame/mlp-tza.d.ts +29 -0
  340. package/dist/tools/frame/mlp-tza.js +186 -0
  341. package/dist/tools/frame/mlp-tza.js.map +1 -0
  342. package/dist/tools/frame/mlp.d.ts +183 -0
  343. package/dist/tools/frame/mlp.js +434 -0
  344. package/dist/tools/frame/mlp.js.map +1 -0
  345. package/dist/tools/frame/ms-exit.d.ts +42 -0
  346. package/dist/tools/frame/ms-exit.js +90 -0
  347. package/dist/tools/frame/ms-exit.js.map +1 -0
  348. package/dist/tools/frame/multi-scale.d.ts +152 -0
  349. package/dist/tools/frame/multi-scale.js +302 -0
  350. package/dist/tools/frame/multi-scale.js.map +1 -0
  351. package/dist/tools/frame/neural-weights.d.ts +6 -5
  352. package/dist/tools/frame/neural-weights.js +234 -235
  353. package/dist/tools/frame/neural-weights.js.map +1 -1
  354. package/dist/tools/frame/neural.js +1 -1
  355. package/dist/tools/frame/neural.js.map +1 -1
  356. package/dist/tools/frame/occluders.d.ts +51 -0
  357. package/dist/tools/frame/occluders.js +72 -0
  358. package/dist/tools/frame/occluders.js.map +1 -0
  359. package/dist/tools/frame/pyramid-layout.d.ts +17 -0
  360. package/dist/tools/frame/pyramid-layout.js +47 -0
  361. package/dist/tools/frame/pyramid-layout.js.map +1 -1
  362. package/dist/tools/frame/shadows.d.ts +110 -0
  363. package/dist/tools/frame/shadows.js +286 -0
  364. package/dist/tools/frame/shadows.js.map +1 -1
  365. package/dist/tools/frame/sparse.d.ts +82 -0
  366. package/dist/tools/frame/sparse.js +242 -1
  367. package/dist/tools/frame/sparse.js.map +1 -1
  368. package/dist/tools/frame/spectral-stack.d.ts +159 -0
  369. package/dist/tools/frame/spectral-stack.js +391 -0
  370. package/dist/tools/frame/spectral-stack.js.map +1 -0
  371. package/dist/tools/frame/spectral.d.ts +21 -2
  372. package/dist/tools/frame/spectral.js +30 -8
  373. package/dist/tools/frame/spectral.js.map +1 -1
  374. package/dist/tools/frame/stack.d.ts +115 -0
  375. package/dist/tools/frame/stack.js +290 -0
  376. package/dist/tools/frame/stack.js.map +1 -0
  377. package/dist/tools/frame/view.d.ts +131 -0
  378. package/dist/tools/frame/view.js +337 -0
  379. package/dist/tools/frame/view.js.map +1 -0
  380. package/dist/tools/index.d.ts +66 -15
  381. package/dist/tools/index.js +55 -11
  382. package/dist/tools/index.js.map +1 -1
  383. package/dist/tools/internal.d.ts +58 -17
  384. package/dist/tools/internal.js +65 -11
  385. package/dist/tools/internal.js.map +1 -1
  386. package/dist/tools/nanovdb/build-from-vdb.d.ts +11 -2
  387. package/dist/tools/nanovdb/build-from-vdb.js +10 -2
  388. package/dist/tools/nanovdb/build-from-vdb.js.map +1 -1
  389. package/dist/tools/nanovdb/bytes.d.ts +17 -4
  390. package/dist/tools/nanovdb/bytes.js +46 -3
  391. package/dist/tools/nanovdb/bytes.js.map +1 -1
  392. package/dist/tools/nanovdb/coarse-first.d.ts +19 -3
  393. package/dist/tools/nanovdb/coarse-first.js +7 -1
  394. package/dist/tools/nanovdb/coarse-first.js.map +1 -1
  395. package/dist/tools/nanovdb/half.d.ts +22 -0
  396. package/dist/tools/nanovdb/half.js +73 -0
  397. package/dist/tools/nanovdb/half.js.map +1 -0
  398. package/dist/tools/nanovdb/index.d.ts +3 -1
  399. package/dist/tools/nanovdb/index.js +2 -1
  400. package/dist/tools/nanovdb/index.js.map +1 -1
  401. package/dist/tools/nanovdb/inspect.d.ts +10 -1
  402. package/dist/tools/nanovdb/inspect.js +8 -1
  403. package/dist/tools/nanovdb/inspect.js.map +1 -1
  404. package/dist/tools/nanovdb/leaf-codec.d.ts +35 -1
  405. package/dist/tools/nanovdb/leaf-codec.js +40 -4
  406. package/dist/tools/nanovdb/leaf-codec.js.map +1 -1
  407. package/dist/tools/nanovdb/quantize.d.ts +39 -10
  408. package/dist/tools/nanovdb/quantize.js +96 -44
  409. package/dist/tools/nanovdb/quantize.js.map +1 -1
  410. package/dist/tools/nanovdb/resample.d.ts +20 -3
  411. package/dist/tools/nanovdb/resample.js +20 -7
  412. package/dist/tools/nanovdb/resample.js.map +1 -1
  413. package/dist/tools/nanovdb/serialize.d.ts +34 -3
  414. package/dist/tools/nanovdb/serialize.js +51 -7
  415. package/dist/tools/nanovdb/serialize.js.map +1 -1
  416. package/dist/tools/nanovdb/stats.d.ts +34 -5
  417. package/dist/tools/nanovdb/stats.js +87 -11
  418. package/dist/tools/nanovdb/stats.js.map +1 -1
  419. package/dist/tools/nanovdb/transform.d.ts +4 -0
  420. package/dist/tools/nanovdb/transform.js +3 -0
  421. package/dist/tools/nanovdb/transform.js.map +1 -1
  422. package/dist/tools/nanovdb/tree.d.ts +14 -3
  423. package/dist/tools/nanovdb/tree.js +25 -13
  424. package/dist/tools/nanovdb/tree.js.map +1 -1
  425. package/dist/tools/nanovdb/write-nvdb.d.ts +47 -12
  426. package/dist/tools/nanovdb/write-nvdb.js +108 -28
  427. package/dist/tools/nanovdb/write-nvdb.js.map +1 -1
  428. package/dist/tools/nvdb-file.d.ts +77 -7
  429. package/dist/tools/nvdb-file.js +177 -20
  430. package/dist/tools/nvdb-file.js.map +1 -1
  431. package/dist/tools/nvdb-stream.d.ts +23 -7
  432. package/dist/tools/nvdb-stream.js +78 -34
  433. package/dist/tools/nvdb-stream.js.map +1 -1
  434. package/dist/tools/reference/analytic.d.ts +41 -0
  435. package/dist/tools/reference/analytic.js +95 -0
  436. package/dist/tools/reference/analytic.js.map +1 -0
  437. package/dist/tools/reference/environment.d.ts +62 -0
  438. package/dist/tools/reference/environment.js +154 -0
  439. package/dist/tools/reference/environment.js.map +1 -0
  440. package/dist/tools/reference/index.d.ts +12 -0
  441. package/dist/tools/reference/index.js +13 -0
  442. package/dist/tools/reference/index.js.map +1 -0
  443. package/dist/tools/reference/media.d.ts +14 -0
  444. package/dist/tools/reference/media.js +30 -0
  445. package/dist/tools/reference/media.js.map +1 -0
  446. package/dist/tools/reference/rng.d.ts +20 -0
  447. package/dist/tools/reference/rng.js +30 -0
  448. package/dist/tools/reference/rng.js.map +1 -0
  449. package/dist/tools/reference/scene.d.ts +312 -0
  450. package/dist/tools/reference/scene.js +169 -0
  451. package/dist/tools/reference/scene.js.map +1 -0
  452. package/dist/tools/reference/tables.d.ts +98 -0
  453. package/dist/tools/reference/tables.js +264 -0
  454. package/dist/tools/reference/tables.js.map +1 -0
  455. package/dist/tools/reference/trace.d.ts +160 -0
  456. package/dist/tools/reference/trace.js +497 -0
  457. package/dist/tools/reference/trace.js.map +1 -0
  458. package/dist/tools/vdb/blosc-write.d.ts +43 -0
  459. package/dist/tools/vdb/blosc-write.js +197 -0
  460. package/dist/tools/vdb/blosc-write.js.map +1 -0
  461. package/dist/tools/vdb/blosc.d.ts +35 -5
  462. package/dist/tools/vdb/blosc.js +82 -26
  463. package/dist/tools/vdb/blosc.js.map +1 -1
  464. package/dist/tools/vdb/blosclz.d.ts +33 -0
  465. package/dist/tools/vdb/blosclz.js +112 -0
  466. package/dist/tools/vdb/blosclz.js.map +1 -0
  467. package/dist/tools/vdb/byte-reader.d.ts +13 -3
  468. package/dist/tools/vdb/byte-reader.js +26 -4
  469. package/dist/tools/vdb/byte-reader.js.map +1 -1
  470. package/dist/tools/vdb/compression.d.ts +13 -5
  471. package/dist/tools/vdb/compression.js +13 -2
  472. package/dist/tools/vdb/compression.js.map +1 -1
  473. package/dist/tools/vdb/grid.js +8 -2
  474. package/dist/tools/vdb/grid.js.map +1 -1
  475. package/dist/tools/vdb/index.d.ts +2 -1
  476. package/dist/tools/vdb/index.js.map +1 -1
  477. package/dist/tools/vdb/lz4.d.ts +30 -0
  478. package/dist/tools/vdb/lz4.js +228 -0
  479. package/dist/tools/vdb/lz4.js.map +1 -0
  480. package/dist/tools/vdb/metadata.js +1 -1
  481. package/dist/tools/vdb/metadata.js.map +1 -1
  482. package/dist/tools/vdb/parse.d.ts +24 -2
  483. package/dist/tools/vdb/parse.js +102 -32
  484. package/dist/tools/vdb/parse.js.map +1 -1
  485. package/dist/tools/vdb/point-render-data.d.ts +49 -1
  486. package/dist/tools/vdb/point-render-data.js +91 -11
  487. package/dist/tools/vdb/point-render-data.js.map +1 -1
  488. package/dist/tools/vdb/points.d.ts +26 -0
  489. package/dist/tools/vdb/points.js +46 -5
  490. package/dist/tools/vdb/points.js.map +1 -1
  491. package/dist/tools/vdb/types.d.ts +59 -2
  492. package/dist/tools/vdb/types.js.map +1 -1
  493. package/dist/tools/wvdb/bake.d.ts +38 -9
  494. package/dist/tools/wvdb/bake.js +63 -13
  495. package/dist/tools/wvdb/bake.js.map +1 -1
  496. package/dist/tools/wvdb/dense.d.ts +80 -1
  497. package/dist/tools/wvdb/dense.js +67 -8
  498. package/dist/tools/wvdb/dense.js.map +1 -1
  499. package/dist/tools/wvdb/format.d.ts +59 -0
  500. package/dist/tools/wvdb/format.js +3 -0
  501. package/dist/tools/wvdb/format.js.map +1 -1
  502. package/dist/tools/wvdb/index.d.ts +1 -0
  503. package/dist/tools/wvdb/index.js +1 -0
  504. package/dist/tools/wvdb/index.js.map +1 -1
  505. package/dist/tools/wvdb/level-set.d.ts +10 -2
  506. package/dist/tools/wvdb/level-set.js.map +1 -1
  507. package/dist/tools/wvdb/nanovdb.d.ts +6 -1
  508. package/dist/tools/wvdb/nanovdb.js +5 -1
  509. package/dist/tools/wvdb/nanovdb.js.map +1 -1
  510. package/dist/tools/wvdb/partial.d.ts +74 -0
  511. package/dist/tools/wvdb/partial.js +233 -0
  512. package/dist/tools/wvdb/partial.js.map +1 -0
  513. package/dist/tools/wvdb/read.d.ts +77 -1
  514. package/dist/tools/wvdb/read.js +30 -7
  515. package/dist/tools/wvdb/read.js.map +1 -1
  516. package/dist/tools/wvdb/write.d.ts +23 -1
  517. package/dist/tools/wvdb/write.js +8 -1
  518. package/dist/tools/wvdb/write.js.map +1 -1
  519. package/package.json +2 -1
  520. package/vendor/VENDOR.md +21 -6
  521. package/vendor/pnanovdb.wgsl +52 -14
  522. package/dist/three/frame/blackbody.d.ts +0 -42
  523. package/dist/three/frame/blackbody.js +0 -74
  524. package/dist/three/frame/blackbody.js.map +0 -1
  525. package/dist/three/frame/chunks.d.ts +0 -157
  526. package/dist/three/frame/chunks.js +0 -559
  527. package/dist/three/frame/chunks.js.map +0 -1
  528. package/dist/three/frame/density-material.d.ts +0 -53
  529. package/dist/three/frame/density-material.js +0 -353
  530. package/dist/three/frame/density-material.js.map +0 -1
  531. package/dist/three/frame/environment-grid-material.d.ts +0 -21
  532. package/dist/three/frame/environment-grid-material.js +0 -184
  533. package/dist/three/frame/environment-grid-material.js.map +0 -1
  534. package/dist/three/frame/environment-material.d.ts +0 -22
  535. package/dist/three/frame/environment-material.js +0 -87
  536. package/dist/three/frame/environment-material.js.map +0 -1
  537. package/dist/three/frame/grid-mip-material.d.ts +0 -12
  538. package/dist/three/frame/grid-mip-material.js +0 -61
  539. package/dist/three/frame/grid-mip-material.js.map +0 -1
  540. package/dist/three/frame/inject-material.d.ts +0 -56
  541. package/dist/three/frame/inject-material.js +0 -424
  542. package/dist/three/frame/inject-material.js.map +0 -1
  543. package/dist/three/frame/integrate-material.d.ts +0 -26
  544. package/dist/three/frame/integrate-material.js +0 -198
  545. package/dist/three/frame/integrate-material.js.map +0 -1
  546. package/dist/three/frame/layout.d.ts +0 -34
  547. package/dist/three/frame/layout.js +0 -48
  548. package/dist/three/frame/layout.js.map +0 -1
  549. package/dist/three/frame/lighting-material.d.ts +0 -41
  550. package/dist/three/frame/lighting-material.js +0 -257
  551. package/dist/three/frame/lighting-material.js.map +0 -1
  552. package/dist/three/frame/lights.d.ts +0 -11
  553. package/dist/three/frame/lights.js +0 -16
  554. package/dist/three/frame/lights.js.map +0 -1
  555. package/dist/three/frame/neural.d.ts +0 -14
  556. package/dist/three/frame/neural.js +0 -105
  557. package/dist/three/frame/neural.js.map +0 -1
  558. package/dist/three/frame/phase.d.ts +0 -44
  559. package/dist/three/frame/phase.js +0 -80
  560. package/dist/three/frame/phase.js.map +0 -1
  561. package/dist/three/frame/shadow-density-material.d.ts +0 -30
  562. package/dist/three/frame/shadow-density-material.js +0 -123
  563. package/dist/three/frame/shadow-density-material.js.map +0 -1
  564. package/dist/three/frame/temporal-material.d.ts +0 -29
  565. package/dist/three/frame/temporal-material.js +0 -152
  566. package/dist/three/frame/temporal-material.js.map +0 -1
  567. package/dist/three/frame/transmittance-material.d.ts +0 -31
  568. package/dist/three/frame/transmittance-material.js +0 -315
  569. package/dist/three/frame/transmittance-material.js.map +0 -1
  570. package/dist/three/frame/view.d.ts +0 -103
  571. package/dist/three/frame/view.js +0 -296
  572. package/dist/three/frame/view.js.map +0 -1
  573. package/dist/three/frame/volume-shadow-material.d.ts +0 -36
  574. package/dist/three/frame/volume-shadow-material.js +0 -128
  575. package/dist/three/frame/volume-shadow-material.js.map +0 -1
  576. package/dist/three/sequence.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"serialize.js","sourceRoot":"","sources":["../../../src/tools/nanovdb/serialize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,EACpB,mCAAmC,EACnC,aAAa,EACb,6BAA6B,EAC7B,8BAA8B,EAC9B,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,cAAc,EACd,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,SAAS,EACT,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EACjB,UAAU,EACV,eAAe,EACf,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,EACd,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,EACnB,wBAAwB,EACxB,yBAAyB,EACzB,yBAAyB,EACzB,yBAAyB,EACzB,0BAA0B,EAC1B,yBAAyB,EACzB,0BAA0B,EAC1B,yBAAyB,EACzB,wBAAwB,EACxB,yBAAyB,EACzB,oBAAoB,EACpB,SAAS,EACT,oBAAoB,EACpB,iBAAiB,EACjB,cAAc,GACf,MAAM,YAAY,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,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AACtB,CAAC","sourcesContent":["/**\n * serialize.ts — lays a {@link BuiltTree} out into a complete, valid NanoVDB\n * FLOAT grid image (a flat little-endian u32 array), and the public\n * `vdbBuildFromDense` entry point.\n *\n * ## Memory layout (32-byte aligned throughout)\n *\n * [GridData 672][TreeData 64][RootData 64 + tiles*32][uppers][lowers][leaves]\n *\n * Every block size is a multiple of 32 (GridData 672, TreeData 64, RootData\n * 64 + 32/tile, upper 270400, lower 33856, leaf 2144), so concatenating from a\n * 32-aligned base keeps every block 32-aligned with no interior padding — this\n * matches the layout native `nanovdb_convert` emits (verified against\n * `sphere_fog_float.nvdb`: tree@672, root@736 (offset 64 from tree), uppers\n * after the root table, etc.).\n *\n * ## Build order\n *\n * 1. buildTree() — voxels -> leaves (value mask + values) -> lower nodes\n * (child leaves + background tiles) -> upper nodes -> root tiles; stats and\n * per-node bbox aggregated bottom-up in that pass.\n * 2. Compute block offsets, allocate the image.\n * 3. Write nodes leaf-first is unnecessary — offsets are known up front, so we\n * write GridData, TreeData, RootData+tiles, uppers, lowers, leaves, patching\n * child offsets (relative to the containing node) as we go.\n *\n * ## nanovdb_convert byte-parity (DEFERRED — needs native tools)\n *\n * This wave's correctness bar is *value* parity through the repo's proven CPU\n * (`read-value.ts`) and WGSL readers, plus structural conformance, NOT byte\n * identity with `nanovdb_convert`. Three things differ from a native encode and\n * are intentionally out of scope here: (a) tile topology: `vdbBuildFromDense`\n * collapses uniform regions into tiles (K4.6, `collapse`), and the leaf path\n * keeps the source's tiles as they are (K4.1), (b) the real Full/Partial CRC checksum (we write the\n * \"disabled\" sentinel — see bytes.ts), and (c) native's trailing grid padding.\n * All three are tracked for the byte-parity follow-up; none affects any value a\n * reader returns.\n */\n\nimport { VDBToolsError } from \"../errors.js\";\nimport {\n CHECKSUM_DISABLED,\n GRID_CLASS_FOG_VOLUME,\n GRID_CLASS_LEVEL_SET,\n GRID_CLASS_STAGGERED,\n GRID_FLAGS_STATS_BBOX_BREADTH_FIRST,\n GRID_NAME_MAX,\n GRID_OFF_BLIND_METADATA_COUNT,\n GRID_OFF_BLIND_METADATA_OFFSET,\n GRID_OFF_CHECKSUM,\n GRID_OFF_DATA0,\n GRID_OFF_DATA1,\n GRID_OFF_DATA2,\n GRID_OFF_FLAGS,\n GRID_OFF_GRID_CLASS,\n GRID_OFF_GRID_COUNT,\n GRID_OFF_GRID_INDEX,\n GRID_OFF_GRID_NAME,\n GRID_OFF_GRID_SIZE,\n GRID_OFF_GRID_TYPE,\n GRID_OFF_MAGIC,\n GRID_OFF_MAP,\n GRID_OFF_VERSION,\n GRID_OFF_VOXEL_SIZE,\n GRID_OFF_WORLD_BBOX,\n GRID_SIZE,\n GridImageWriter,\n LOWER_OFF_CHILD_MASK,\n LOWER_TABLE_COUNT,\n MAGIC_GRID,\n MAP_OFF_INVMATD,\n MAP_OFF_INVMATF,\n MAP_OFF_MATD,\n MAP_OFF_MATF,\n MAP_OFF_TAPERD,\n MAP_OFF_TAPERF,\n MAP_OFF_VECD,\n MAP_OFF_VECF,\n NODE_FLAG_STATS,\n NODE_OFF_BBOX_MAX,\n NODE_OFF_BBOX_MIN,\n NODE_OFF_FLAGS,\n NODE_OFF_VALUE_MASK,\n ROOT_OFF_BBOX_MAX,\n ROOT_OFF_BBOX_MIN,\n ROOT_OFF_TABLE_SIZE,\n ROOT_TILE_OFF_CHILD,\n ROOT_TILE_OFF_KEY,\n ROOT_TILE_OFF_STATE,\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_LOWER,\n TREE_OFF_NODE_OFFSET_ROOT,\n TREE_OFF_NODE_OFFSET_UPPER,\n TREE_OFF_TILE_COUNT_LOWER,\n TREE_OFF_TILE_COUNT_ROOT,\n TREE_OFF_TILE_COUNT_UPPER,\n TREE_OFF_VOXEL_COUNT,\n TREE_SIZE,\n UPPER_OFF_CHILD_MASK,\n UPPER_TABLE_COUNT,\n VERSION_PACKED,\n} from \"./bytes.js\";\nimport { VDB_FLOAT_LEAF_CODEC, type VDBLeafCodec, writeVec3StatsBlock } from \"./leaf-codec.js\";\nimport { StatsAccumulator } from \"./stats.js\";\nimport {\n buildTree,\n buildTreeFromLeaves,\n type BuiltTree,\n type LeafInput,\n type LowerNode,\n type TileInput,\n type TileValue,\n type UpperNode,\n} from \"./tree.js\";\n\nexport interface VDBBuildFromDenseOptions {\n /** Index-space min corner of the dense block. Default [0,0,0]. */\n origin?: [number, number, number];\n /**\n * Voxel size in world units: a number (uniform), or `[x, y, z]` for an\n * anisotropic, axis-aligned Map (diagonal scale, as `vdbResampleGrid`\n * writes). Default 1.\n */\n voxelSize?: number | [number, number, number];\n /** World-space position of index coord `origin`. Default `origin * voxelSize` (per axis). */\n worldOrigin?: [number, number, number];\n /** Background (inactive) value. Default 0. */\n background?: number;\n /**\n * Active predicate. Omitted: active iff `value !== background` (exact).\n * Given: active iff `|value - background| > activeThreshold`.\n */\n activeThreshold?: number;\n /** Grid name (<256 bytes incl. NUL). Default \"dense\". */\n gridName?: string;\n /** Grid class. Default \"FogVolume\". */\n gridClass?: GridClassName;\n /**\n * Collapse uniform regions into tiles, as OpenVDB `tools::prune` at\n * tolerance 0 (K4.6): a leaf whose voxels are all active (or all inactive)\n * with one value becomes a lower-node tile, a lower node made only of equal\n * tiles an upper-node tile, and so on. Values read back identically.\n * Default true: a dense build has no native topology to keep.\n */\n collapse?: boolean;\n}\n\n/** Grid classes the serializer writes (NanoVDB `GridClass`). */\nexport type GridClassName = \"FogVolume\" | \"LevelSet\" | \"Staggered\" | \"Unknown\";\n\n/** Result of a build, exposing metadata alongside the raw image. */\nexport interface VDBBuiltGrid {\n image: Uint32Array;\n gridName: string;\n voxelCount: number;\n indexBBox: { min: [number, number, number]; max: [number, number, number] };\n worldBBox: { min: [number, number, number]; max: [number, number, number] };\n /** Voxel size along x: the voxel size of a uniform grid. See {@link VDBBuiltGrid.voxelSizeXYZ} for all three. */\n voxelSize: number;\n /** Voxel size per axis (equal for a uniform grid; an anisotropic grid has a diagonal, non-uniform Map). */\n voxelSizeXYZ: [number, number, number];\n nodeCounts: { leaf: number; lower: number; upper: number };\n /** Active tiles per level (all 0 unless the source had active tiles). */\n tileCounts: { lower: number; upper: number; root: number };\n}\n\nconst GRID_CLASS_ID: Record<GridClassName, number> = {\n FogVolume: GRID_CLASS_FOG_VOLUME,\n LevelSet: GRID_CLASS_LEVEL_SET,\n Staggered: GRID_CLASS_STAGGERED,\n Unknown: 0,\n};\n\n/**\n * Builds a complete FLOAT NanoVDB grid image from a dense array of shape\n * `[nx,ny,nz]` (x-major: idx = (x*ny + y)*nz + z).\n */\nexport function vdbBuildFromDense(\n values: Float32Array,\n dims: [number, number, number],\n opts: VDBBuildFromDenseOptions = {},\n): Uint32Array {\n return vdbBuildFromDenseDetailed(values, dims, opts).image;\n}\n\n/** As `vdbBuildFromDense`, but also returns computed metadata (used by writeNvdb). */\nexport function vdbBuildFromDenseDetailed(\n values: Float32Array,\n dims: [number, number, number],\n opts: VDBBuildFromDenseOptions = {},\n): VDBBuiltGrid {\n const [nx, ny, nz] = dims;\n if (nx < 0 || ny < 0 || nz < 0 || !Number.isInteger(nx) || !Number.isInteger(ny) || !Number.isInteger(nz)) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", `vdbBuildFromDense: dims must be non-negative integers, got [${nx},${ny},${nz}]`);\n }\n if (values.length !== nx * ny * nz) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", \n `vdbBuildFromDense: values.length ${values.length} !== nx*ny*nz (${nx}*${ny}*${nz} = ${nx * ny * nz})`,\n );\n }\n\n const origin = opts.origin ?? [0, 0, 0];\n const voxelSizeXYZ = voxelSizeVec3(opts.voxelSize, \"vdbBuildFromDense\");\n const background = opts.background ?? 0;\n const gridName = opts.gridName ?? \"dense\";\n const gridClassId = GRID_CLASS_ID[opts.gridClass ?? \"FogVolume\"];\n const worldOrigin: [number, number, number] =\n opts.worldOrigin ?? [origin[0] * voxelSizeXYZ[0], origin[1] * voxelSizeXYZ[1], origin[2] * voxelSizeXYZ[2]];\n\n const nameBytes = new TextEncoder().encode(gridName);\n if (nameBytes.length + 1 > GRID_NAME_MAX) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", \n `vdbBuildFromDense: gridName is ${nameBytes.length} bytes; must be < ${GRID_NAME_MAX} (incl. NUL). ` +\n `Long grid names (HasLongGridName + blind metadata) are not supported in v1.`,\n );\n }\n\n const codec = VDB_FLOAT_LEAF_CODEC;\n const tree = buildTree(values, dims, {\n origin,\n background,\n activeThreshold: opts.activeThreshold,\n collapse: opts.collapse ?? true,\n });\n\n const image = layoutGrid(tree, codec, {\n gridName,\n nameBytes,\n gridClassId,\n voxelSize: voxelSizeXYZ,\n worldOrigin,\n origin,\n background,\n });\n\n const indexBBox = bboxOrEmpty(tree.root);\n const worldBBox = worldBBoxFromIndex(indexBBox, voxelSizeXYZ, worldOrigin, origin);\n\n return {\n image,\n gridName,\n voxelCount: tree.activeVoxelCount,\n indexBBox,\n worldBBox,\n voxelSize: voxelSizeXYZ[0],\n voxelSizeXYZ,\n nodeCounts: { leaf: tree.leaves.length, lower: tree.lowers.length, upper: tree.uppers.length },\n tileCounts: { ...tree.tileCounts },\n };\n}\n\n/** A `voxelSize` option (number or `[x, y, z]`, default 1) as a validated per-axis vector. */\nfunction voxelSizeVec3(vs: number | readonly number[] | undefined, fn: string): [number, number, number] {\n const v = vs ?? 1;\n const xyz: [number, number, number] = typeof v === \"number\" ? [v, v, v] : [v[0]!, v[1]!, v[2]!];\n if ((typeof v !== \"number\" && v.length !== 3) || !xyz.every((c) => Number.isFinite(c) && c > 0)) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", `${fn}: voxelSize must be positive and finite (a number or [x, y, z]), got ${JSON.stringify(vs)}`);\n }\n return xyz;\n}\n\nexport interface VDBBuildFromLeavesOptions {\n /**\n * Voxel size in world units: a number (uniform), or `[x, y, z]` for an\n * anisotropic, axis-aligned Map (diagonal scale). Default 1.\n */\n voxelSize?: number | [number, number, number];\n /** World-space translation (the NanoVDB Map's vec / index-origin world pos). Default [0,0,0]. */\n worldOrigin?: [number, number, number];\n /** Background (inactive) value: a number, or `[x, y, z]` for a Vec3f codec. Default 0. */\n background?: TileValue;\n /** Grid name (<256 bytes incl. NUL). Default \"grid\". */\n gridName?: string;\n /** Grid class. Default \"FogVolume\". */\n gridClass?: GridClassName;\n /**\n * Active tiles above leaf level (8^3 lower-node, 128^3 upper-node and 4096^3\n * root tiles), written as NanoVDB tiles rather than expanded into leaves. A\n * tile may not share a slot with a leaf or child node. Default: none.\n */\n tiles?: Iterable<TileInput>;\n /**\n * Collapse uniform leaves and nodes into tiles (OpenVDB `prune`, tolerance 0;\n * K4.6). Default false: this is the re-encoding path (`quantize`,\n * `buildFromVdb`), which keeps the source's topology so an image of a native\n * input keeps native's node counts and sizes.\n */\n collapse?: boolean;\n}\n\n/**\n * Builds a complete NanoVDB grid image from an iterator of already-materialised\n * leaves (each carrying its 8-aligned origin, all 512 values and a 512-bit value\n * mask), using the given {@link VDBLeafCodec}. This is the memory-frugal path —\n * leaves stream in, no dense array is ever allocated — that backs `buildFromVdb`\n * (parser leaves -> FLOAT) and `quantize` (an existing grid's leaves -> Fp8/FpN).\n */\nexport function vdbBuildFromLeavesDetailed(\n leaves: Iterable<LeafInput>,\n codec: VDBLeafCodec,\n opts: VDBBuildFromLeavesOptions = {},\n): VDBBuiltGrid {\n const voxelSizeXYZ = voxelSizeVec3(opts.voxelSize, \"buildFromLeaves\");\n const components = codec.components ?? 1;\n const background: TileValue = opts.background ?? (components === 3 ? [0, 0, 0] : 0);\n if ((typeof background === \"number\") !== (components === 1)) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", `buildFromLeaves: background must have ${components} component(s) for this codec`);\n }\n const gridName = opts.gridName ?? \"grid\";\n const gridClassId = GRID_CLASS_ID[opts.gridClass ?? \"FogVolume\"];\n const worldOrigin = opts.worldOrigin ?? [0, 0, 0];\n\n const nameBytes = new TextEncoder().encode(gridName);\n if (nameBytes.length + 1 > GRID_NAME_MAX) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", \n `buildFromLeaves: gridName is ${nameBytes.length} bytes; must be < ${GRID_NAME_MAX} (incl. NUL). ` +\n `Long grid names (HasLongGridName + blind metadata) are not supported in v1.`,\n );\n }\n\n const tree = buildTreeFromLeaves(leaves, opts.tiles, components, { collapse: opts.collapse === true, background });\n const image = layoutGrid(tree, codec, {\n gridName,\n nameBytes,\n gridClassId,\n voxelSize: voxelSizeXYZ,\n worldOrigin,\n origin: [0, 0, 0],\n background,\n });\n\n const indexBBox = bboxOrEmpty(tree.root);\n const worldBBox = worldBBoxFromIndex(indexBBox, voxelSizeXYZ, worldOrigin, [0, 0, 0]);\n\n return {\n image,\n gridName,\n voxelCount: tree.activeVoxelCount,\n indexBBox,\n worldBBox,\n voxelSize: voxelSizeXYZ[0],\n voxelSizeXYZ,\n nodeCounts: { leaf: tree.leaves.length, lower: tree.lowers.length, upper: tree.uppers.length },\n tileCounts: { ...tree.tileCounts },\n };\n}\n\ninterface LayoutParams {\n gridName: string;\n nameBytes: Uint8Array;\n gridClassId: number;\n voxelSize: [number, number, number];\n worldOrigin: [number, number, number];\n origin: [number, number, number];\n background: TileValue;\n}\n\nfunction layoutGrid(tree: BuiltTree, codec: VDBLeafCodec, p: LayoutParams): Uint32Array {\n const L = codec.layout;\n const nTiles = tree.rootTiles.length;\n const nUpper = tree.uppers.length;\n const nLower = tree.lowers.length;\n const nLeaf = tree.leaves.length;\n\n // Block base offsets (all multiples of 32).\n const treeOff = GRID_SIZE; // 672\n const rootOff = treeOff + TREE_SIZE; // 736\n const rootBlockSize = L.rootSize + nTiles * L.rootTileSize;\n const upperOff = rootOff + rootBlockSize;\n const lowerOff = upperOff + nUpper * L.upperSize;\n const leafOff = lowerOff + nLower * L.lowerSize;\n\n // Per-leaf plans + cumulative offsets. FLOAT/Fp8 leaves are fixed-size; FpN\n // leaves vary (96 + bitWidth*64), so the block is not a uniform stride.\n const leafPlans = tree.leaves.map((leaf) => codec.planLeaf(leaf.values));\n const leafByteOffset = new Array<number>(nLeaf);\n let leafAcc = 0;\n for (let i = 0; i < nLeaf; i++) {\n leafByteOffset[i] = leafAcc;\n leafAcc += leafPlans[i]!.byteSize;\n }\n const total = leafOff + leafAcc;\n\n const w = new GridImageWriter(total);\n\n const upperAbs = (i: number): number => upperOff + i * L.upperSize;\n const lowerAbs = (i: number): number => lowerOff + i * L.lowerSize;\n const leafAbs = (i: number): number => leafOff + leafByteOffset[i]!;\n\n // ---- GridData ----------------------------------------------------------\n writeGridData(w, tree, codec, p, total);\n\n // ---- TreeData ----------------------------------------------------------\n w.setU64(treeOff + TREE_OFF_NODE_OFFSET_LEAF, BigInt(leafOff - treeOff));\n w.setU64(treeOff + TREE_OFF_NODE_OFFSET_LOWER, BigInt(lowerOff - treeOff));\n w.setU64(treeOff + TREE_OFF_NODE_OFFSET_UPPER, BigInt(upperOff - treeOff));\n w.setU64(treeOff + TREE_OFF_NODE_OFFSET_ROOT, BigInt(rootOff - treeOff));\n w.setU32(treeOff + TREE_OFF_NODE_COUNT_LEAF, nLeaf);\n w.setU32(treeOff + TREE_OFF_NODE_COUNT_LOWER, nLower);\n w.setU32(treeOff + TREE_OFF_NODE_COUNT_UPPER, nUpper);\n // Active tiles exist only when the leaf-path source supplied them (K4.1).\n w.setU32(treeOff + TREE_OFF_TILE_COUNT_LOWER, tree.tileCounts.lower);\n w.setU32(treeOff + TREE_OFF_TILE_COUNT_UPPER, tree.tileCounts.upper);\n w.setU32(treeOff + TREE_OFF_TILE_COUNT_ROOT, tree.tileCounts.root);\n w.setU64(treeOff + TREE_OFF_VOXEL_COUNT, BigInt(tree.activeVoxelCount));\n\n // ---- RootData + tiles --------------------------------------------------\n const ibox = bboxOrEmpty(tree.root);\n writeCoord(w, rootOff + ROOT_OFF_BBOX_MIN, ibox.min);\n writeCoord(w, rootOff + ROOT_OFF_BBOX_MAX, ibox.max);\n w.setU32(rootOff + ROOT_OFF_TABLE_SIZE, nTiles);\n codec.writeConstant(w, rootOff + L.rootOffBackground, p.background);\n writeStats(w, codec, rootOff, L.rootOffMin, L.rootOffMax, L.rootOffAve, L.rootOffStdDev, tree.root);\n\n tree.rootTiles.forEach((tile, i) => {\n const tileOff = rootOff + L.rootSize + i * L.rootTileSize;\n w.setU64(tileOff + ROOT_TILE_OFF_KEY, tile.key);\n if (tile.child) {\n w.setI64(tileOff + ROOT_TILE_OFF_CHILD, BigInt(upperAbs(tile.child.memIndex) - rootOff));\n w.setU32(tileOff + ROOT_TILE_OFF_STATE, 0);\n // Child slot: the value field stays zero (the image is zero-filled).\n } else {\n // Root tile: no child (offset 0), state on (active) or off (inactive), the tile's value.\n w.setI64(tileOff + ROOT_TILE_OFF_CHILD, 0n);\n w.setU32(tileOff + ROOT_TILE_OFF_STATE, tile.active ? 1 : 0);\n codec.writeConstant(w, tileOff + L.rootTileOffValue, tile.value);\n }\n });\n\n // ---- Upper nodes -------------------------------------------------------\n for (const upper of tree.uppers) {\n writeInternalNode(w, upperAbs(upper.memIndex), upper, {\n tableCount: UPPER_TABLE_COUNT,\n childMaskOff: UPPER_OFF_CHILD_MASK,\n tableOff: L.upperOffTable,\n tableStride: L.tableStride,\n offMin: L.upperOffMin,\n offMax: L.upperOffMax,\n offAve: L.upperOffAve,\n offStdDev: L.upperOffStdDev,\n background: p.background,\n codec,\n childAbs: lowerAbs,\n });\n }\n\n // ---- Lower nodes -------------------------------------------------------\n for (const lower of tree.lowers) {\n writeInternalNode(w, lowerAbs(lower.memIndex), lower, {\n tableCount: LOWER_TABLE_COUNT,\n childMaskOff: LOWER_OFF_CHILD_MASK,\n tableOff: L.lowerOffTable,\n tableStride: L.tableStride,\n offMin: L.lowerOffMin,\n offMax: L.lowerOffMax,\n offAve: L.lowerOffAve,\n offStdDev: L.lowerOffStdDev,\n background: p.background,\n codec,\n childAbs: leafAbs,\n });\n }\n\n // ---- Leaf nodes --------------------------------------------------------\n for (const leaf of tree.leaves) {\n codec.encodeLeaf(w, leafAbs(leaf.memIndex), leaf, leafPlans[leaf.memIndex]!);\n }\n\n return w.u32;\n}\n\ninterface InternalNodeWriteParams {\n tableCount: number;\n childMaskOff: number;\n tableOff: number;\n tableStride: number;\n offMin: number;\n offMax: number;\n offAve: number;\n offStdDev: number;\n background: TileValue;\n codec: VDBLeafCodec;\n /** Absolute byte offset of child with the given memIndex. */\n childAbs: (memIndex: number) => number;\n}\n\nfunction writeInternalNode(\n w: GridImageWriter,\n nodeOff: number,\n node: UpperNode | LowerNode,\n p: InternalNodeWriteParams,\n): void {\n const s = node.stats;\n const bmin = s.isEmpty ? node.origin : s.bboxMin;\n const bmax = s.isEmpty ? node.origin : s.bboxMax;\n writeCoord(w, nodeOff + NODE_OFF_BBOX_MIN, bmin);\n writeCoord(w, nodeOff + NODE_OFF_BBOX_MAX, bmax);\n w.setU64(nodeOff + NODE_OFF_FLAGS, BigInt(NODE_FLAG_STATS));\n writeStats(w, p.codec, nodeOff, p.offMin, p.offMax, p.offAve, p.offStdDev, s);\n\n // Table: child slots hold an i64 offset (relative to this node); active\n // tiles set their value-mask bit and hold the tile value; every other slot\n // is an inactive background tile carrying the background value.\n const childSlots = node.children;\n const tiles = node.tiles;\n const inactiveTiles = node.inactiveTiles;\n const backgroundIsZero =\n typeof p.background === \"number\" ? p.background === 0 : p.background.every((c) => c === 0);\n for (let n = 0; n < p.tableCount; n++) {\n const slotOff = nodeOff + p.tableOff + n * p.tableStride;\n const child = childSlots.get(n);\n const tileValue = tiles.size > 0 ? tiles.get(n) : undefined;\n if (child !== undefined) {\n w.setMaskBit(nodeOff + p.childMaskOff, n);\n w.setI64(slotOff, BigInt(p.childAbs(child.memIndex) - nodeOff));\n } else if (tileValue !== undefined) {\n w.setMaskBit(nodeOff + NODE_OFF_VALUE_MASK, n);\n p.codec.writeConstant(w, slotOff, tileValue);\n } else if (inactiveTiles.size > 0 && inactiveTiles.has(n)) {\n p.codec.writeConstant(w, slotOff, inactiveTiles.get(n)!);\n } else if (!backgroundIsZero) {\n // Skip when background is 0: the buffer is already zero-filled.\n p.codec.writeConstant(w, slotOff, p.background);\n }\n }\n}\n\nfunction writeStats(\n w: GridImageWriter,\n codec: VDBLeafCodec,\n base: number,\n offMin: number,\n offMax: number,\n offAve: number,\n offStdDev: number,\n s: StatsAccumulator,\n): void {\n if (codec.components === 3) {\n writeVec3StatsBlock(w, base, offMin, offMax, offAve, offStdDev, s);\n return;\n }\n w.setF32(base + offMin, s.isEmpty ? 0 : s.min);\n w.setF32(base + offMax, s.isEmpty ? 0 : s.max);\n w.setF32(base + offAve, s.average);\n w.setF32(base + offStdDev, s.stdDev);\n}\n\nfunction writeGridData(\n w: GridImageWriter,\n tree: BuiltTree,\n codec: VDBLeafCodec,\n p: LayoutParams,\n total: number,\n): void {\n w.setU64(GRID_OFF_MAGIC, MAGIC_GRID);\n w.setU64(GRID_OFF_CHECKSUM, CHECKSUM_DISABLED);\n w.setU32(GRID_OFF_VERSION, VERSION_PACKED);\n w.setU32(GRID_OFF_FLAGS, GRID_FLAGS_STATS_BBOX_BREADTH_FIRST);\n w.setU32(GRID_OFF_GRID_INDEX, 0);\n w.setU32(GRID_OFF_GRID_COUNT, 1);\n w.setU64(GRID_OFF_GRID_SIZE, BigInt(total));\n // Grid name: C string in the fixed 256-byte inline field.\n w.setBytes(GRID_OFF_GRID_NAME, p.nameBytes); // NUL terminator already zero\n writeMap(w, p);\n writeWorldBBox(w, tree, p);\n const vs = p.voxelSize;\n w.setF64(GRID_OFF_VOXEL_SIZE, vs[0]);\n w.setF64(GRID_OFF_VOXEL_SIZE + 8, vs[1]);\n w.setF64(GRID_OFF_VOXEL_SIZE + 16, vs[2]);\n w.setU32(GRID_OFF_GRID_CLASS, p.gridClassId);\n w.setU32(GRID_OFF_GRID_TYPE, codec.layout.gridType);\n // No blind metadata: offset points at end-of-grid, count 0 (native\n // convention, verified on sphere_fog_float.nvdb).\n w.setU64(GRID_OFF_BLIND_METADATA_OFFSET, BigInt(total));\n w.setU32(GRID_OFF_BLIND_METADATA_COUNT, 0);\n w.setU32(GRID_OFF_DATA0, 0);\n w.setU64(GRID_OFF_DATA1, 0n);\n w.setU64(GRID_OFF_DATA2, 0n);\n}\n\nfunction writeMap(w: GridImageWriter, p: LayoutParams): void {\n const s = p.voxelSize;\n const t: [number, number, number] = [\n p.worldOrigin[0] - p.origin[0] * s[0],\n p.worldOrigin[1] - p.origin[1] * s[1],\n p.worldOrigin[2] - p.origin[2] * s[2],\n ];\n const mat = [s[0], 0, 0, 0, s[1], 0, 0, 0, s[2]];\n const invMat = [1 / s[0], 0, 0, 0, 1 / s[1], 0, 0, 0, 1 / s[2]];\n const mapBase = GRID_OFF_MAP;\n for (let i = 0; i < 9; i++) {\n w.setF32(mapBase + MAP_OFF_MATF + i * 4, mat[i]!);\n w.setF32(mapBase + MAP_OFF_INVMATF + i * 4, invMat[i]!);\n w.setF64(mapBase + MAP_OFF_MATD + i * 8, mat[i]!);\n w.setF64(mapBase + MAP_OFF_INVMATD + i * 8, invMat[i]!);\n }\n for (let i = 0; i < 3; i++) {\n w.setF32(mapBase + MAP_OFF_VECF + i * 4, t[i]!);\n w.setF64(mapBase + MAP_OFF_VECD + i * 8, t[i]!);\n }\n w.setF32(mapBase + MAP_OFF_TAPERF, 1);\n w.setF64(mapBase + MAP_OFF_TAPERD, 1);\n}\n\nfunction writeWorldBBox(w: GridImageWriter, tree: BuiltTree, p: LayoutParams): void {\n const ibox = bboxOrEmpty(tree.root);\n const wb = worldBBoxFromIndex(ibox, p.voxelSize, p.worldOrigin, p.origin);\n for (let a = 0; a < 3; a++) w.setF64(GRID_OFF_WORLD_BBOX + a * 8, wb.min[a]!);\n for (let a = 0; a < 3; a++) w.setF64(GRID_OFF_WORLD_BBOX + 24 + a * 8, wb.max[a]!);\n}\n\n// ---------------------------------------------------------------------------\n// Small helpers\n// ---------------------------------------------------------------------------\n\nfunction writeCoord(w: GridImageWriter, off: number, c: readonly [number, number, number]): void {\n w.setI32(off, c[0]);\n w.setI32(off + 4, c[1]);\n w.setI32(off + 8, c[2]);\n}\n\nfunction bboxOrEmpty(s: StatsAccumulator): {\n min: [number, number, number];\n max: [number, number, number];\n} {\n if (s.isEmpty) return { min: [0, 0, 0], max: [-1, -1, -1] };\n return { min: [...s.bboxMin], max: [...s.bboxMax] };\n}\n\nfunction worldBBoxFromIndex(\n ibox: { min: [number, number, number]; max: [number, number, number] },\n voxelSize: [number, number, number],\n worldOrigin: [number, number, number],\n origin: [number, number, number],\n): { min: [number, number, number]; max: [number, number, number] } {\n const t = [\n worldOrigin[0] - origin[0] * voxelSize[0],\n worldOrigin[1] - origin[1] * voxelSize[1],\n worldOrigin[2] - origin[2] * voxelSize[2],\n ];\n const min: [number, number, number] = [0, 0, 0];\n const max: [number, number, number] = [0, 0, 0];\n for (let a = 0; a < 3; a++) {\n min[a] = ibox.min[a]! * voxelSize[a]! + t[a]!;\n // \"+ one voxel\" convention: world max corner is (indexMax + 1) * voxelSize.\n max[a] = (ibox.max[a]! + 1) * voxelSize[a]! + t[a]!;\n }\n return { min, max };\n}\n"]}
1
+ {"version":3,"file":"serialize.js","sourceRoot":"","sources":["../../../src/tools/nanovdb/serialize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,EACpB,mCAAmC,EACnC,cAAc,EACd,aAAa,EACb,6BAA6B,EAC7B,8BAA8B,EAC9B,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,cAAc,EACd,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EACl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AO,CAAC,EAAE,CAAC;AACtD,CAAC;AAED,SAAS,kBAAkB,CACzB,IAAsE,EACtE,SAAmC,EACnC,WAAqC,EACrC,MAAgC;IAEhC,MAAM,CAAC,GAAG;QACR,WAAW,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC;QACzC,WAAW,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC;QACzC,WAAW,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC;KAC1C,CAAC;IACF,MAAM,GAAG,GAA6B,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAChD,MAAM,GAAG,GAA6B,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAChD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAE,GAAG,SAAS,CAAC,CAAC,CAAE,GAAG,CAAC,CAAC,CAAC,CAAE,CAAC;QAC9C,4EAA4E;QAC5E,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAE,GAAG,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAE,GAAG,CAAC,CAAC,CAAC,CAAE,CAAC;IACtD,CAAC;IACD,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AACtB,CAAC","sourcesContent":["/**\n * serialize.ts — lays a {@link BuiltTree} out into a complete, valid NanoVDB\n * FLOAT grid image (a flat little-endian u32 array), and the public\n * `vdbBuildFromDense` entry point.\n *\n * ## Memory layout (32-byte aligned throughout)\n *\n * [GridData 672][TreeData 64][RootData 64 + tiles*32][uppers][lowers][leaves]\n *\n * Every block size is a multiple of 32 (GridData 672, TreeData 64, RootData\n * 64 + 32/tile, upper 270400, lower 33856, leaf 2144), so concatenating from a\n * 32-aligned base keeps every block 32-aligned with no interior padding — this\n * matches the layout native `nanovdb_convert` emits (verified against\n * `sphere_fog_float.nvdb`: tree@672, root@736 (offset 64 from tree), uppers\n * after the root table, etc.).\n *\n * ## Build order\n *\n * 1. buildTree() — voxels -> leaves (value mask + values) -> lower nodes\n * (child leaves + background tiles) -> upper nodes -> root tiles; stats and\n * per-node bbox aggregated bottom-up in that pass.\n * 2. Compute block offsets, allocate the image.\n * 3. Write nodes leaf-first is unnecessary — offsets are known up front, so we\n * write GridData, TreeData, RootData+tiles, uppers, lowers, leaves, patching\n * child offsets (relative to the containing node) as we go.\n *\n * ## nanovdb_convert byte-parity (DEFERRED — needs native tools)\n *\n * This wave's correctness bar is *value* parity through the repo's proven CPU\n * (`read-value.ts`) and WGSL readers, plus structural conformance, NOT byte\n * identity with `nanovdb_convert`. Three things differ from a native encode and\n * are intentionally out of scope here: (a) tile topology: `vdbBuildFromDense`\n * collapses uniform regions into tiles (K4.6, `collapse`), and the leaf path\n * keeps the source's tiles as they are (K4.1), (b) the real Full/Partial CRC checksum (we write the\n * \"disabled\" sentinel — see bytes.ts), and (c) native's trailing grid padding.\n * All three are tracked for the byte-parity follow-up; none affects any value a\n * reader returns.\n */\n\nimport { VDBToolsError } from \"../errors.js\";\nimport {\n CHECKSUM_DISABLED,\n GRID_CLASS_FOG_VOLUME,\n GRID_CLASS_LEVEL_SET,\n GRID_CLASS_STAGGERED,\n GRID_FLAGS_STATS_BBOX_BREADTH_FIRST,\n GRID_TYPE_HALF,\n GRID_NAME_MAX,\n GRID_OFF_BLIND_METADATA_COUNT,\n GRID_OFF_BLIND_METADATA_OFFSET,\n GRID_OFF_CHECKSUM,\n GRID_OFF_DATA0,\n GRID_OFF_DATA1,\n GRID_OFF_DATA2,\n GRID_OFF_FLAGS,\n GRID_OFF_GRID_CLASS,\n GRID_OFF_GRID_COUNT,\n GRID_OFF_GRID_INDEX,\n GRID_OFF_GRID_NAME,\n GRID_OFF_GRID_SIZE,\n GRID_OFF_GRID_TYPE,\n GRID_OFF_MAGIC,\n GRID_OFF_MAP,\n GRID_OFF_VERSION,\n GRID_OFF_VOXEL_SIZE,\n GRID_OFF_WORLD_BBOX,\n GRID_SIZE,\n GridImageWriter,\n LOWER_OFF_CHILD_MASK,\n LOWER_TABLE_COUNT,\n MAGIC_GRID,\n MAP_OFF_INVMATD,\n MAP_OFF_INVMATF,\n MAP_OFF_MATD,\n MAP_OFF_MATF,\n MAP_OFF_TAPERD,\n MAP_OFF_TAPERF,\n MAP_OFF_VECD,\n MAP_OFF_VECF,\n NODE_FLAG_STATS,\n NODE_OFF_BBOX_MAX,\n NODE_OFF_BBOX_MIN,\n NODE_OFF_FLAGS,\n NODE_OFF_VALUE_MASK,\n ROOT_OFF_BBOX_MAX,\n ROOT_OFF_BBOX_MIN,\n ROOT_OFF_TABLE_SIZE,\n ROOT_TILE_OFF_CHILD,\n ROOT_TILE_OFF_KEY,\n ROOT_TILE_OFF_STATE,\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_LOWER,\n TREE_OFF_NODE_OFFSET_ROOT,\n TREE_OFF_NODE_OFFSET_UPPER,\n TREE_OFF_TILE_COUNT_LOWER,\n TREE_OFF_TILE_COUNT_ROOT,\n TREE_OFF_TILE_COUNT_UPPER,\n TREE_OFF_VOXEL_COUNT,\n TREE_SIZE,\n UPPER_OFF_CHILD_MASK,\n UPPER_TABLE_COUNT,\n VERSION_PACKED,\n} from \"./bytes.js\";\nimport { VDB_FLOAT_LEAF_CODEC, type VDBLeafCodec, writeVec3StatsBlock } from \"./leaf-codec.js\";\nimport { STATS_FLOAT_MAX, STATS_HALF_MAX, StatsAccumulator } from \"./stats.js\";\nimport {\n buildTree,\n buildTreeFromLeaves,\n type BuiltTree,\n type LeafInput,\n type LowerNode,\n type TileInput,\n type TileValue,\n type UpperNode,\n type VDBDenseLayout,\n} from \"./tree.js\";\n\n/** Options of {@link vdbBuildFromDense}. */\nexport interface VDBBuildFromDenseOptions {\n /** Index-space min corner of the dense block. Default [0,0,0]. */\n origin?: [number, number, number];\n /**\n * Voxel size in world units: a number (uniform), or `[x, y, z]` for an\n * anisotropic, axis-aligned Map (diagonal scale, as `vdbResampleGrid`\n * writes). Default 1.\n */\n voxelSize?: number | [number, number, number];\n /** World-space position of index coord `origin`. Default `origin * voxelSize` (per axis). */\n worldOrigin?: [number, number, number];\n /** Background (inactive) value. Default 0. */\n background?: number;\n /**\n * Active predicate. Omitted: active iff `value !== background` (exact).\n * Given: active iff `|value - background| > activeThreshold`.\n */\n activeThreshold?: number;\n /** Grid name (<256 bytes incl. NUL). Default \"dense\". */\n gridName?: string;\n /** Grid class. Default \"FogVolume\". */\n gridClass?: GridClassName;\n /**\n * Collapse uniform regions into tiles, as OpenVDB `tools::prune` at\n * tolerance 0 (K4.6): a leaf whose voxels are all active (or all inactive)\n * with one value becomes a lower-node tile, a lower node made only of equal\n * tiles an upper-node tile, and so on. Values read back identically.\n * Default true: a dense build has no native topology to keep.\n */\n collapse?: boolean;\n /**\n * How `values` is laid out (P1.17). `'x-major'` (default): `idx = (x * ny + y) * nz + z`, z fastest.\n * `'x-fastest'`: `idx = x + nx * (y + ny * z)`, the order of a 3D texture and of most simulation arrays; the\n * array is read in place (no transposed copy) and the image equals the one built from the transposed array, byte\n * for byte.\n */\n layout?: VDBDenseLayout;\n}\n\n/** Grid classes the serializer writes (NanoVDB `GridClass`). */\nexport type GridClassName = \"FogVolume\" | \"LevelSet\" | \"Staggered\" | \"Unknown\";\n\n/** Result of a build, exposing metadata alongside the raw image. */\nexport interface VDBBuiltGrid {\n /** The grid image (little-endian u32 words, `GridData` at word 0). */\n image: Uint32Array;\n /** The grid's name. */\n gridName: string;\n /** Active voxel count. */\n voxelCount: number;\n /** Inclusive index-space box of the active voxels. */\n indexBBox: { min: [number, number, number]; max: [number, number, number] };\n /** World-space box (its max is one voxel beyond the max voxel's centre). */\n worldBBox: { min: [number, number, number]; max: [number, number, number] };\n /** Voxel size along x: the voxel size of a uniform grid. See {@link VDBBuiltGrid.voxelSizeXYZ} for all three. */\n voxelSize: number;\n /** Voxel size per axis (equal for a uniform grid; an anisotropic grid has a diagonal, non-uniform Map). */\n voxelSizeXYZ: [number, number, number];\n /** Number of nodes per level. */\n nodeCounts: { leaf: number; lower: number; upper: number };\n /** Active tiles per level (all 0 unless the source had active tiles). */\n tileCounts: { lower: number; upper: number; root: number };\n}\n\nconst GRID_CLASS_ID: Record<GridClassName, number> = {\n FogVolume: GRID_CLASS_FOG_VOLUME,\n LevelSet: GRID_CLASS_LEVEL_SET,\n Staggered: GRID_CLASS_STAGGERED,\n Unknown: 0,\n};\n\n/**\n * Builds a complete FLOAT NanoVDB grid image from a dense array of shape\n * `[nx,ny,nz]` (x-major: idx = (x*ny + y)*nz + z; `layout: 'x-fastest'` reads\n * idx = x + nx*(y + ny*z) instead). With `collapse` (the default) an 8^3 block\n * of one value becomes a tile of its lower node, not a leaf.\n *\n * @param values The dense values, `nx * ny * nz` of them.\n * @param dims Voxels per axis `[nx, ny, nz]`.\n * @param opts Origin, voxel size, background, activity rule, name, class, collapsing and the array layout.\n */\nexport function vdbBuildFromDense(\n values: Float32Array,\n dims: [number, number, number],\n opts: VDBBuildFromDenseOptions = {},\n): Uint32Array {\n return vdbBuildFromDenseDetailed(values, dims, opts).image;\n}\n\n/**\n * As `vdbBuildFromDense`, but also returns computed metadata (used by writeNvdb).\n *\n * @param values The dense values, `nx * ny * nz` of them.\n * @param dims Voxels per axis `[nx, ny, nz]`.\n * @param opts Origin, voxel size, background, activity rule, name, class and collapsing.\n */\nexport function vdbBuildFromDenseDetailed(\n values: Float32Array,\n dims: [number, number, number],\n opts: VDBBuildFromDenseOptions = {},\n): VDBBuiltGrid {\n const [nx, ny, nz] = dims;\n if (nx < 0 || ny < 0 || nz < 0 || !Number.isInteger(nx) || !Number.isInteger(ny) || !Number.isInteger(nz)) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", `vdbBuildFromDense: dims must be non-negative integers, got [${nx},${ny},${nz}]`);\n }\n if (values.length !== nx * ny * nz) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", \n `vdbBuildFromDense: values.length ${values.length} !== nx*ny*nz (${nx}*${ny}*${nz} = ${nx * ny * nz})`,\n );\n }\n\n const layout = opts.layout ?? \"x-major\";\n if (layout !== \"x-major\" && layout !== \"x-fastest\") {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", `vdbBuildFromDense: unknown layout \"${String(layout)}\" (expected \"x-major\" or \"x-fastest\")`);\n }\n const origin = opts.origin ?? [0, 0, 0];\n const voxelSizeXYZ = voxelSizeVec3(opts.voxelSize, \"vdbBuildFromDense\");\n const background = opts.background ?? 0;\n const gridName = opts.gridName ?? \"dense\";\n const gridClassId = GRID_CLASS_ID[opts.gridClass ?? \"FogVolume\"];\n const worldOrigin: [number, number, number] =\n opts.worldOrigin ?? [origin[0] * voxelSizeXYZ[0], origin[1] * voxelSizeXYZ[1], origin[2] * voxelSizeXYZ[2]];\n\n const nameBytes = new TextEncoder().encode(gridName);\n if (nameBytes.length + 1 > GRID_NAME_MAX) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", \n `vdbBuildFromDense: gridName is ${nameBytes.length} bytes; must be < ${GRID_NAME_MAX} (incl. NUL). ` +\n `Long grid names (HasLongGridName + blind metadata) are not supported in v1.`,\n );\n }\n\n const codec = VDB_FLOAT_LEAF_CODEC;\n const tree = buildTree(values, dims, {\n origin,\n background,\n activeThreshold: opts.activeThreshold,\n collapse: opts.collapse ?? true,\n layout,\n });\n\n const image = layoutGrid(tree, codec, {\n gridName,\n nameBytes,\n gridClassId,\n voxelSize: voxelSizeXYZ,\n worldOrigin,\n origin,\n background,\n });\n\n const indexBBox = bboxOrEmpty(tree.root);\n const worldBBox = worldBBoxFromIndex(indexBBox, voxelSizeXYZ, worldOrigin, origin);\n\n return {\n image,\n gridName,\n voxelCount: tree.activeVoxelCount,\n indexBBox,\n worldBBox,\n voxelSize: voxelSizeXYZ[0],\n voxelSizeXYZ,\n nodeCounts: { leaf: tree.leaves.length, lower: tree.lowers.length, upper: tree.uppers.length },\n tileCounts: { ...tree.tileCounts },\n };\n}\n\n/** A `voxelSize` option (number or `[x, y, z]`, default 1) as a validated per-axis vector. */\nfunction voxelSizeVec3(vs: number | readonly number[] | undefined, fn: string): [number, number, number] {\n const v = vs ?? 1;\n const xyz: [number, number, number] = typeof v === \"number\" ? [v, v, v] : [v[0]!, v[1]!, v[2]!];\n if ((typeof v !== \"number\" && v.length !== 3) || !xyz.every((c) => Number.isFinite(c) && c > 0)) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", `${fn}: voxelSize must be positive and finite (a number or [x, y, z]), got ${JSON.stringify(vs)}`);\n }\n return xyz;\n}\n\n/** Options of {@link vdbBuildFromLeavesDetailed}. */\nexport interface VDBBuildFromLeavesOptions {\n /**\n * Voxel size in world units: a number (uniform), or `[x, y, z]` for an\n * anisotropic, axis-aligned Map (diagonal scale). Default 1.\n */\n voxelSize?: number | [number, number, number];\n /** World-space translation (the NanoVDB Map's vec / index-origin world pos). Default [0,0,0]. */\n worldOrigin?: [number, number, number];\n /** Background (inactive) value: a number, or `[x, y, z]` for a Vec3f codec. Default 0. */\n background?: TileValue;\n /** Grid name (<256 bytes incl. NUL). Default \"grid\". */\n gridName?: string;\n /** Grid class. Default \"FogVolume\". */\n gridClass?: GridClassName;\n /**\n * Active tiles above leaf level (8^3 lower-node, 128^3 upper-node and 4096^3\n * root tiles), written as NanoVDB tiles rather than expanded into leaves. A\n * tile may not share a slot with a leaf or child node. Default: none.\n */\n tiles?: Iterable<TileInput>;\n /**\n * Collapse uniform leaves and nodes into tiles (OpenVDB `prune`, tolerance 0;\n * K4.6). Default false: this is the re-encoding path (`quantize`,\n * `buildFromVdb`), which keeps the source's topology so an image of a native\n * input keeps native's node counts and sizes.\n */\n collapse?: boolean;\n}\n\n/**\n * Builds a complete NanoVDB grid image from an iterator of already-materialised\n * leaves (each carrying its 8-aligned origin, all 512 values and a 512-bit value\n * mask), using the given {@link VDBLeafCodec}. This is the memory-frugal path —\n * leaves stream in, no dense array is ever allocated — that backs `buildFromVdb`\n * (parser leaves -> FLOAT) and `quantize` (an existing grid's leaves -> Fp8/FpN).\n *\n * @param leaves The leaves, in any order.\n * @param codec Encodes the leaves and constants (e.g. `VDB_FP8_LEAF_CODEC`).\n * @param opts Voxel size, origin, background, name, class, tiles and collapsing.\n */\nexport function vdbBuildFromLeavesDetailed(\n leaves: Iterable<LeafInput>,\n codec: VDBLeafCodec,\n opts: VDBBuildFromLeavesOptions = {},\n): VDBBuiltGrid {\n const voxelSizeXYZ = voxelSizeVec3(opts.voxelSize, \"buildFromLeaves\");\n const components = codec.components ?? 1;\n const background: TileValue = opts.background ?? (components === 3 ? [0, 0, 0] : 0);\n if ((typeof background === \"number\") !== (components === 1)) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", `buildFromLeaves: background must have ${components} component(s) for this codec`);\n }\n const gridName = opts.gridName ?? \"grid\";\n const gridClassId = GRID_CLASS_ID[opts.gridClass ?? \"FogVolume\"];\n const worldOrigin = opts.worldOrigin ?? [0, 0, 0];\n\n const nameBytes = new TextEncoder().encode(gridName);\n if (nameBytes.length + 1 > GRID_NAME_MAX) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", \n `buildFromLeaves: gridName is ${nameBytes.length} bytes; must be < ${GRID_NAME_MAX} (incl. NUL). ` +\n `Long grid names (HasLongGridName + blind metadata) are not supported in v1.`,\n );\n }\n\n const round = components === 1 ? codec.roundValue : undefined;\n const tree = round\n ? buildTreeFromLeaves(roundLeaves(leaves, round), roundTiles(opts.tiles, round), components, {\n collapse: opts.collapse === true,\n background: round(background as number),\n })\n : buildTreeFromLeaves(leaves, opts.tiles, components, { collapse: opts.collapse === true, background });\n const image = layoutGrid(tree, codec, {\n gridName,\n nameBytes,\n gridClassId,\n voxelSize: voxelSizeXYZ,\n worldOrigin,\n origin: [0, 0, 0],\n background,\n });\n\n const indexBBox = bboxOrEmpty(tree.root);\n const worldBBox = worldBBoxFromIndex(indexBBox, voxelSizeXYZ, worldOrigin, [0, 0, 0]);\n\n return {\n image,\n gridName,\n voxelCount: tree.activeVoxelCount,\n indexBBox,\n worldBBox,\n voxelSize: voxelSizeXYZ[0],\n voxelSizeXYZ,\n nodeCounts: { leaf: tree.leaves.length, lower: tree.lowers.length, upper: tree.uppers.length },\n tileCounts: { ...tree.tileCounts },\n };\n}\n\n/** Leaves with every value passed through the codec's `roundValue` (a copy; the input is not touched). */\nfunction* roundLeaves(leaves: Iterable<LeafInput>, round: (v: number) => number): Iterable<LeafInput> {\n for (const leaf of leaves) {\n const values = new Float32Array(leaf.values.length);\n for (let n = 0; n < values.length; n++) values[n] = round(leaf.values[n]!);\n yield { ...leaf, values };\n }\n}\n\nfunction roundTiles(tiles: Iterable<TileInput> | undefined, round: (v: number) => number): TileInput[] | undefined {\n if (tiles === undefined) return undefined;\n return [...tiles].map((t) => ({ ...t, value: typeof t.value === \"number\" ? round(t.value) : t.value }));\n}\n\ninterface LayoutParams {\n gridName: string;\n nameBytes: Uint8Array;\n gridClassId: number;\n voxelSize: [number, number, number];\n worldOrigin: [number, number, number];\n origin: [number, number, number];\n background: TileValue;\n}\n\nfunction layoutGrid(tree: BuiltTree, codec: VDBLeafCodec, p: LayoutParams): Uint32Array {\n const L = codec.layout;\n const nTiles = tree.rootTiles.length;\n const nUpper = tree.uppers.length;\n const nLower = tree.lowers.length;\n const nLeaf = tree.leaves.length;\n\n // Block base offsets (all multiples of 32).\n const treeOff = GRID_SIZE; // 672\n const rootOff = treeOff + TREE_SIZE; // 736\n const rootBlockSize = L.rootSize + nTiles * L.rootTileSize;\n const upperOff = rootOff + rootBlockSize;\n const lowerOff = upperOff + nUpper * L.upperSize;\n const leafOff = lowerOff + nLower * L.lowerSize;\n\n // Per-leaf plans + cumulative offsets. FLOAT/Fp8 leaves are fixed-size; FpN\n // leaves vary (96 + bitWidth*64), so the block is not a uniform stride.\n const leafPlans = tree.leaves.map((leaf) => codec.planLeaf(leaf.values));\n const leafByteOffset = new Array<number>(nLeaf);\n let leafAcc = 0;\n for (let i = 0; i < nLeaf; i++) {\n leafByteOffset[i] = leafAcc;\n leafAcc += leafPlans[i]!.byteSize;\n }\n const total = leafOff + leafAcc;\n\n const w = new GridImageWriter(total);\n\n const upperAbs = (i: number): number => upperOff + i * L.upperSize;\n const lowerAbs = (i: number): number => lowerOff + i * L.lowerSize;\n const leafAbs = (i: number): number => leafOff + leafByteOffset[i]!;\n\n // ---- GridData ----------------------------------------------------------\n writeGridData(w, tree, codec, p, total);\n\n // ---- TreeData ----------------------------------------------------------\n w.setU64(treeOff + TREE_OFF_NODE_OFFSET_LEAF, BigInt(leafOff - treeOff));\n w.setU64(treeOff + TREE_OFF_NODE_OFFSET_LOWER, BigInt(lowerOff - treeOff));\n w.setU64(treeOff + TREE_OFF_NODE_OFFSET_UPPER, BigInt(upperOff - treeOff));\n w.setU64(treeOff + TREE_OFF_NODE_OFFSET_ROOT, BigInt(rootOff - treeOff));\n w.setU32(treeOff + TREE_OFF_NODE_COUNT_LEAF, nLeaf);\n w.setU32(treeOff + TREE_OFF_NODE_COUNT_LOWER, nLower);\n w.setU32(treeOff + TREE_OFF_NODE_COUNT_UPPER, nUpper);\n // Active tiles exist only when the leaf-path source supplied them (K4.1).\n w.setU32(treeOff + TREE_OFF_TILE_COUNT_LOWER, tree.tileCounts.lower);\n w.setU32(treeOff + TREE_OFF_TILE_COUNT_UPPER, tree.tileCounts.upper);\n w.setU32(treeOff + TREE_OFF_TILE_COUNT_ROOT, tree.tileCounts.root);\n w.setU64(treeOff + TREE_OFF_VOXEL_COUNT, BigInt(tree.activeVoxelCount));\n\n // ---- RootData + tiles --------------------------------------------------\n const ibox = bboxOrEmpty(tree.root);\n writeCoord(w, rootOff + ROOT_OFF_BBOX_MIN, ibox.min);\n writeCoord(w, rootOff + ROOT_OFF_BBOX_MAX, ibox.max);\n w.setU32(rootOff + ROOT_OFF_TABLE_SIZE, nTiles);\n codec.writeConstant(w, rootOff + L.rootOffBackground, p.background);\n writeStats(w, codec, rootOff, L.rootOffMin, L.rootOffMax, L.rootOffAve, L.rootOffStdDev, tree.root);\n\n tree.rootTiles.forEach((tile, i) => {\n const tileOff = rootOff + L.rootSize + i * L.rootTileSize;\n w.setU64(tileOff + ROOT_TILE_OFF_KEY, tile.key);\n if (tile.child) {\n w.setI64(tileOff + ROOT_TILE_OFF_CHILD, BigInt(upperAbs(tile.child.memIndex) - rootOff));\n w.setU32(tileOff + ROOT_TILE_OFF_STATE, 0);\n // Child slot: the value field stays zero (the image is zero-filled).\n } else {\n // Root tile: no child (offset 0), state on (active) or off (inactive), the tile's value.\n w.setI64(tileOff + ROOT_TILE_OFF_CHILD, 0n);\n w.setU32(tileOff + ROOT_TILE_OFF_STATE, tile.active ? 1 : 0);\n codec.writeConstant(w, tileOff + L.rootTileOffValue, tile.value);\n }\n });\n\n // ---- Upper nodes -------------------------------------------------------\n for (const upper of tree.uppers) {\n writeInternalNode(w, upperAbs(upper.memIndex), upper, {\n tableCount: UPPER_TABLE_COUNT,\n childMaskOff: UPPER_OFF_CHILD_MASK,\n tableOff: L.upperOffTable,\n tableStride: L.tableStride,\n offMin: L.upperOffMin,\n offMax: L.upperOffMax,\n offAve: L.upperOffAve,\n offStdDev: L.upperOffStdDev,\n background: p.background,\n codec,\n childAbs: lowerAbs,\n });\n }\n\n // ---- Lower nodes -------------------------------------------------------\n for (const lower of tree.lowers) {\n writeInternalNode(w, lowerAbs(lower.memIndex), lower, {\n tableCount: LOWER_TABLE_COUNT,\n childMaskOff: LOWER_OFF_CHILD_MASK,\n tableOff: L.lowerOffTable,\n tableStride: L.tableStride,\n offMin: L.lowerOffMin,\n offMax: L.lowerOffMax,\n offAve: L.lowerOffAve,\n offStdDev: L.lowerOffStdDev,\n background: p.background,\n codec,\n childAbs: leafAbs,\n });\n }\n\n // ---- Leaf nodes --------------------------------------------------------\n for (const leaf of tree.leaves) {\n codec.encodeLeaf(w, leafAbs(leaf.memIndex), leaf, leafPlans[leaf.memIndex]!);\n }\n\n return w.u32;\n}\n\ninterface InternalNodeWriteParams {\n tableCount: number;\n childMaskOff: number;\n tableOff: number;\n tableStride: number;\n offMin: number;\n offMax: number;\n offAve: number;\n offStdDev: number;\n background: TileValue;\n codec: VDBLeafCodec;\n /** Absolute byte offset of child with the given memIndex. */\n childAbs: (memIndex: number) => number;\n}\n\nfunction writeInternalNode(\n w: GridImageWriter,\n nodeOff: number,\n node: UpperNode | LowerNode,\n p: InternalNodeWriteParams,\n): void {\n const s = node.stats;\n const bmin = s.isEmpty ? node.origin : s.bboxMin;\n const bmax = s.isEmpty ? node.origin : s.bboxMax;\n writeCoord(w, nodeOff + NODE_OFF_BBOX_MIN, bmin);\n writeCoord(w, nodeOff + NODE_OFF_BBOX_MAX, bmax);\n w.setU64(nodeOff + NODE_OFF_FLAGS, BigInt(NODE_FLAG_STATS));\n writeStats(w, p.codec, nodeOff, p.offMin, p.offMax, p.offAve, p.offStdDev, s);\n\n // Table: child slots hold an i64 offset (relative to this node); active\n // tiles set their value-mask bit and hold the tile value; every other slot\n // is an inactive background tile carrying the background value.\n const childSlots = node.children;\n const tiles = node.tiles;\n const inactiveTiles = node.inactiveTiles;\n const backgroundIsZero =\n typeof p.background === \"number\" ? p.background === 0 : p.background.every((c) => c === 0);\n for (let n = 0; n < p.tableCount; n++) {\n const slotOff = nodeOff + p.tableOff + n * p.tableStride;\n const child = childSlots.get(n);\n const tileValue = tiles.size > 0 ? tiles.get(n) : undefined;\n if (child !== undefined) {\n w.setMaskBit(nodeOff + p.childMaskOff, n);\n w.setI64(slotOff, BigInt(p.childAbs(child.memIndex) - nodeOff));\n } else if (tileValue !== undefined) {\n w.setMaskBit(nodeOff + NODE_OFF_VALUE_MASK, n);\n p.codec.writeConstant(w, slotOff, tileValue);\n } else if (inactiveTiles.size > 0 && inactiveTiles.has(n)) {\n p.codec.writeConstant(w, slotOff, inactiveTiles.get(n)!);\n } else if (!backgroundIsZero) {\n // Skip when background is 0: the buffer is already zero-filled.\n p.codec.writeConstant(w, slotOff, p.background);\n }\n }\n}\n\nfunction writeStats(\n w: GridImageWriter,\n codec: VDBLeafCodec,\n base: number,\n offMin: number,\n offMax: number,\n offAve: number,\n offStdDev: number,\n s: StatsAccumulator,\n): void {\n if (codec.components === 3) {\n writeVec3StatsBlock(w, base, offMin, offMax, offAve, offStdDev, s);\n return;\n }\n // Min/max have the grid's value type (f32, or binary16 for Half); ave/stddev are f32.\n // Extrema's start value (the type's largest finite) stays when a node holds only +-inf (K7.H1).\n const finiteMax = codec.layout.gridType === GRID_TYPE_HALF ? STATS_HALF_MAX : STATS_FLOAT_MAX;\n codec.writeConstant(w, base + offMin, s.storedMin(finiteMax));\n codec.writeConstant(w, base + offMax, s.storedMax(finiteMax));\n w.setF32(base + offAve, s.average);\n w.setF32(base + offStdDev, s.stdDev);\n}\n\nfunction writeGridData(\n w: GridImageWriter,\n tree: BuiltTree,\n codec: VDBLeafCodec,\n p: LayoutParams,\n total: number,\n): void {\n w.setU64(GRID_OFF_MAGIC, MAGIC_GRID);\n w.setU64(GRID_OFF_CHECKSUM, CHECKSUM_DISABLED);\n w.setU32(GRID_OFF_VERSION, VERSION_PACKED);\n w.setU32(GRID_OFF_FLAGS, GRID_FLAGS_STATS_BBOX_BREADTH_FIRST);\n w.setU32(GRID_OFF_GRID_INDEX, 0);\n w.setU32(GRID_OFF_GRID_COUNT, 1);\n w.setU64(GRID_OFF_GRID_SIZE, BigInt(total));\n // Grid name: C string in the fixed 256-byte inline field.\n w.setBytes(GRID_OFF_GRID_NAME, p.nameBytes); // NUL terminator already zero\n writeMap(w, p);\n writeWorldBBox(w, tree, p);\n const vs = p.voxelSize;\n w.setF64(GRID_OFF_VOXEL_SIZE, vs[0]);\n w.setF64(GRID_OFF_VOXEL_SIZE + 8, vs[1]);\n w.setF64(GRID_OFF_VOXEL_SIZE + 16, vs[2]);\n w.setU32(GRID_OFF_GRID_CLASS, p.gridClassId);\n w.setU32(GRID_OFF_GRID_TYPE, codec.layout.gridType);\n // No blind metadata: offset points at end-of-grid, count 0 (native\n // convention, verified on sphere_fog_float.nvdb).\n w.setU64(GRID_OFF_BLIND_METADATA_OFFSET, BigInt(total));\n w.setU32(GRID_OFF_BLIND_METADATA_COUNT, 0);\n w.setU32(GRID_OFF_DATA0, 0);\n w.setU64(GRID_OFF_DATA1, 0n);\n w.setU64(GRID_OFF_DATA2, 0n);\n}\n\nfunction writeMap(w: GridImageWriter, p: LayoutParams): void {\n const s = p.voxelSize;\n const t: [number, number, number] = [\n p.worldOrigin[0] - p.origin[0] * s[0],\n p.worldOrigin[1] - p.origin[1] * s[1],\n p.worldOrigin[2] - p.origin[2] * s[2],\n ];\n const mat = [s[0], 0, 0, 0, s[1], 0, 0, 0, s[2]];\n const invMat = [1 / s[0], 0, 0, 0, 1 / s[1], 0, 0, 0, 1 / s[2]];\n const mapBase = GRID_OFF_MAP;\n for (let i = 0; i < 9; i++) {\n w.setF32(mapBase + MAP_OFF_MATF + i * 4, mat[i]!);\n w.setF32(mapBase + MAP_OFF_INVMATF + i * 4, invMat[i]!);\n w.setF64(mapBase + MAP_OFF_MATD + i * 8, mat[i]!);\n w.setF64(mapBase + MAP_OFF_INVMATD + i * 8, invMat[i]!);\n }\n for (let i = 0; i < 3; i++) {\n w.setF32(mapBase + MAP_OFF_VECF + i * 4, t[i]!);\n w.setF64(mapBase + MAP_OFF_VECD + i * 8, t[i]!);\n }\n w.setF32(mapBase + MAP_OFF_TAPERF, 1);\n w.setF64(mapBase + MAP_OFF_TAPERD, 1);\n}\n\nfunction writeWorldBBox(w: GridImageWriter, tree: BuiltTree, p: LayoutParams): void {\n const ibox = bboxOrEmpty(tree.root);\n const wb = worldBBoxFromIndex(ibox, p.voxelSize, p.worldOrigin, p.origin);\n for (let a = 0; a < 3; a++) w.setF64(GRID_OFF_WORLD_BBOX + a * 8, wb.min[a]!);\n for (let a = 0; a < 3; a++) w.setF64(GRID_OFF_WORLD_BBOX + 24 + a * 8, wb.max[a]!);\n}\n\n// ---------------------------------------------------------------------------\n// Small helpers\n// ---------------------------------------------------------------------------\n\nfunction writeCoord(w: GridImageWriter, off: number, c: readonly [number, number, number]): void {\n w.setI32(off, c[0]);\n w.setI32(off + 4, c[1]);\n w.setI32(off + 8, c[2]);\n}\n\nfunction bboxOrEmpty(s: StatsAccumulator): {\n min: [number, number, number];\n max: [number, number, number];\n} {\n if (s.isEmpty) return { min: [0, 0, 0], max: [-1, -1, -1] };\n return { min: [...s.bboxMin], max: [...s.bboxMax] };\n}\n\nfunction worldBBoxFromIndex(\n ibox: { min: [number, number, number]; max: [number, number, number] },\n voxelSize: [number, number, number],\n worldOrigin: [number, number, number],\n origin: [number, number, number],\n): { min: [number, number, number]; max: [number, number, number] } {\n const t = [\n worldOrigin[0] - origin[0] * voxelSize[0],\n worldOrigin[1] - origin[1] * voxelSize[1],\n worldOrigin[2] - origin[2] * voxelSize[2],\n ];\n const min: [number, number, number] = [0, 0, 0];\n const max: [number, number, number] = [0, 0, 0];\n for (let a = 0; a < 3; a++) {\n min[a] = ibox.min[a]! * voxelSize[a]! + t[a]!;\n // \"+ one voxel\" convention: world max corner is (indexMax + 1) * voxelSize.\n max[a] = (ibox.max[a]! + 1) * voxelSize[a]! + t[a]!;\n }\n return { min, max };\n}\n"]}
@@ -6,17 +6,34 @@
6
6
  * are the exact aggregate of its children's plus its own active tiles, each
7
7
  * tile counted with GridStats' weight (see {@link StatsAccumulator.addTile}).
8
8
  *
9
- * The accumulator keeps N, sum and sum-of-squares in f64 so that ave/stddev are
10
- * computed at full precision before being narrowed to the f32 stored in the
11
- * grid. These stats feed the material's adaptive stepping (invariant D), so they
12
- * are computed for real, not stubbed.
9
+ * Two accumulations (K7.H1, DIVERGES V73), chosen by
10
+ * {@link vdbSetStatsAccumulation} when an accumulator is made:
11
+ * - `'welford'` (default since K7.H1): GridStats' own f64 update, ported
12
+ * operation for operation (`Stats<T, 0>::add(val)`, `add(val, n)`,
13
+ * `add(other)`). Fed in GridStats' order (leaf voxels by offset, an internal
14
+ * node's active tiles then its children by slot, the root table in order) it
15
+ * reproduces native ave/stddev bit for bit, ±∞ leaves included (NaN there).
16
+ * - `'sums'` (K1–K7.H): f64 count, sum and sum of squares; ave/stddev within a
17
+ * few f32 ulp of native, ±∞ where Welford gives NaN.
18
+ * Either way ave/stddev are narrowed to f32 only when stored.
13
19
  */
20
+ /** How {@link StatsAccumulator} accumulates ave/stddev (K7.H1 A/B; see the file header). */
21
+ export type VDBStatsAccumulation = "welford" | "sums";
22
+ /**
23
+ * Sets how accumulators made from now on compute ave/stddev, and returns the previous setting.
24
+ * Internal (tests and A/B scripts); builds made under one setting are consistent.
25
+ */
26
+ export declare function vdbSetStatsAccumulation(mode: VDBStatsAccumulation): VDBStatsAccumulation;
14
27
  /** Running active-value statistics plus the tight index-space bbox of the
15
28
  * active voxels they cover. */
16
29
  export declare class StatsAccumulator {
30
+ /** Samples (with tiles: GridStats weight, see {@link addTile}). */
17
31
  count: number;
32
+ readonly mode: VDBStatsAccumulation;
18
33
  private sum;
19
34
  private sumSq;
35
+ private avg;
36
+ private aux;
20
37
  min: number;
21
38
  max: number;
22
39
  bboxMin: [number, number, number];
@@ -30,13 +47,25 @@ export declare class StatsAccumulator {
30
47
  * not a voxel count.
31
48
  */
32
49
  addTile(value: number, weight: number, bboxMin: readonly [number, number, number], bboxMax: readonly [number, number, number]): void;
33
- /** Merges a child accumulator's totals into this one. */
50
+ /** Merges a child accumulator's totals into this one (both must use the same accumulation). */
34
51
  merge(child: StatsAccumulator): void;
35
52
  get average(): number;
36
53
  /** Population standard deviation (GridStats convention). */
37
54
  get stdDev(): number;
38
55
  get isEmpty(): boolean;
56
+ /**
57
+ * `min` as GridStats' `Extrema` stores it: Extrema starts at the value type's largest finite value
58
+ * (`finiteMax`: FLT_MAX for Float, 65504 for Half), so a node whose values are all +∞ keeps that
59
+ * start value as its minimum (K7.H1). 0 when empty.
60
+ */
61
+ storedMin(finiteMax: number): number;
62
+ /** `max` as GridStats stores it: −`finiteMax` when every value is −∞ (see {@link storedMin}). 0 when empty. */
63
+ storedMax(finiteMax: number): number;
39
64
  }
65
+ /** FLT_MAX, `std::numeric_limits<float>::max()`: GridStats' starting minimum for f32 values. */
66
+ export declare const STATS_FLOAT_MAX = 3.4028234663852886e+38;
67
+ /** 65504, the largest finite binary16: GridStats' starting minimum for Half values (raw 0x7BFF). */
68
+ export declare const STATS_HALF_MAX = 65504;
40
69
  /** `Vec3<float>::lengthSqr()` evaluated in f32: `x*x + y*y + z*z`, left to right. */
41
70
  export declare function lengthSqrF32(x: number, y: number, z: number): number;
42
71
  /**
@@ -6,19 +6,43 @@
6
6
  * are the exact aggregate of its children's plus its own active tiles, each
7
7
  * tile counted with GridStats' weight (see {@link StatsAccumulator.addTile}).
8
8
  *
9
- * The accumulator keeps N, sum and sum-of-squares in f64 so that ave/stddev are
10
- * computed at full precision before being narrowed to the f32 stored in the
11
- * grid. These stats feed the material's adaptive stepping (invariant D), so they
12
- * are computed for real, not stubbed.
9
+ * Two accumulations (K7.H1, DIVERGES V73), chosen by
10
+ * {@link vdbSetStatsAccumulation} when an accumulator is made:
11
+ * - `'welford'` (default since K7.H1): GridStats' own f64 update, ported
12
+ * operation for operation (`Stats<T, 0>::add(val)`, `add(val, n)`,
13
+ * `add(other)`). Fed in GridStats' order (leaf voxels by offset, an internal
14
+ * node's active tiles then its children by slot, the root table in order) it
15
+ * reproduces native ave/stddev bit for bit, ±∞ leaves included (NaN there).
16
+ * - `'sums'` (K1–K7.H): f64 count, sum and sum of squares; ave/stddev within a
17
+ * few f32 ulp of native, ±∞ where Welford gives NaN.
18
+ * Either way ave/stddev are narrowed to f32 only when stored.
13
19
  */
14
20
  const INT_MIN = -0x80000000;
15
21
  const INT_MAX = 0x7fffffff;
22
+ let accumulation = "welford";
23
+ /**
24
+ * Sets how accumulators made from now on compute ave/stddev, and returns the previous setting.
25
+ * Internal (tests and A/B scripts); builds made under one setting are consistent.
26
+ */
27
+ export function vdbSetStatsAccumulation(mode) {
28
+ if (mode !== "welford" && mode !== "sums")
29
+ throw new RangeError(`stats accumulation must be 'welford' or 'sums', got ${String(mode)}`);
30
+ const previous = accumulation;
31
+ accumulation = mode;
32
+ return previous;
33
+ }
16
34
  /** Running active-value statistics plus the tight index-space bbox of the
17
35
  * active voxels they cover. */
18
36
  export class StatsAccumulator {
37
+ /** Samples (with tiles: GridStats weight, see {@link addTile}). */
19
38
  count = 0;
39
+ mode = accumulation;
40
+ // 'sums'
20
41
  sum = 0;
21
42
  sumSq = 0;
43
+ // 'welford': GridStats' mAvg, mAux.
44
+ avg = 0;
45
+ aux = 0;
22
46
  min = Number.POSITIVE_INFINITY;
23
47
  max = Number.NEGATIVE_INFINITY;
24
48
  // Tight bbox of active voxels (inclusive). Empty when count === 0.
@@ -27,8 +51,16 @@ export class StatsAccumulator {
27
51
  /** Adds one active voxel at index coord (x,y,z) with the given value. */
28
52
  addVoxel(value, x, y, z) {
29
53
  this.count += 1;
30
- this.sum += value;
31
- this.sumSq += value * value;
54
+ if (this.mode === "welford") {
55
+ // Stats<T, 0>::add(val)
56
+ const delta = value - this.avg;
57
+ this.avg += delta / this.count;
58
+ this.aux += delta * (value - this.avg);
59
+ }
60
+ else {
61
+ this.sum += value;
62
+ this.sumSq += value * value;
63
+ }
32
64
  if (value < this.min)
33
65
  this.min = value;
34
66
  if (value > this.max)
@@ -53,9 +85,18 @@ export class StatsAccumulator {
53
85
  * not a voxel count.
54
86
  */
55
87
  addTile(value, weight, bboxMin, bboxMax) {
88
+ if (this.mode === "welford") {
89
+ // Stats<T, 0>::add(val, n), left to right as C++ evaluates it.
90
+ const denom = 1.0 / (this.count + weight);
91
+ const delta = value - this.avg;
92
+ this.avg += denom * delta * weight;
93
+ this.aux += denom * delta * delta * this.count * weight;
94
+ }
95
+ else {
96
+ this.sum += value * weight;
97
+ this.sumSq += value * value * weight;
98
+ }
56
99
  this.count += weight;
57
- this.sum += value * weight;
58
- this.sumSq += value * value * weight;
59
100
  if (value < this.min)
60
101
  this.min = value;
61
102
  if (value > this.max)
@@ -67,13 +108,24 @@ export class StatsAccumulator {
67
108
  this.bboxMax[a] = bboxMax[a];
68
109
  }
69
110
  }
70
- /** Merges a child accumulator's totals into this one. */
111
+ /** Merges a child accumulator's totals into this one (both must use the same accumulation). */
71
112
  merge(child) {
72
113
  if (child.count === 0)
73
114
  return;
115
+ if (child.mode !== this.mode)
116
+ throw new RangeError("StatsAccumulator.merge: the accumulators use different accumulations");
117
+ if (this.mode === "welford") {
118
+ // Stats<T, 0>::add(const Stats& other): mAux += other.mAux + (…).
119
+ const denom = 1.0 / (this.count + child.count);
120
+ const delta = child.avg - this.avg;
121
+ this.avg += denom * delta * child.count;
122
+ this.aux += child.aux + denom * delta * delta * this.count * child.count;
123
+ }
124
+ else {
125
+ this.sum += child.sum;
126
+ this.sumSq += child.sumSq;
127
+ }
74
128
  this.count += child.count;
75
- this.sum += child.sum;
76
- this.sumSq += child.sumSq;
77
129
  if (child.min < this.min)
78
130
  this.min = child.min;
79
131
  if (child.max > this.max)
@@ -86,10 +138,14 @@ export class StatsAccumulator {
86
138
  }
87
139
  }
88
140
  get average() {
141
+ if (this.mode === "welford")
142
+ return this.avg;
89
143
  return this.count > 0 ? this.sum / this.count : 0;
90
144
  }
91
145
  /** Population standard deviation (GridStats convention). */
92
146
  get stdDev() {
147
+ if (this.mode === "welford")
148
+ return this.count < 2 ? 0 : Math.sqrt(this.aux / this.count);
93
149
  if (this.count === 0)
94
150
  return 0;
95
151
  const mean = this.sum / this.count;
@@ -99,7 +155,27 @@ export class StatsAccumulator {
99
155
  get isEmpty() {
100
156
  return this.count === 0;
101
157
  }
158
+ /**
159
+ * `min` as GridStats' `Extrema` stores it: Extrema starts at the value type's largest finite value
160
+ * (`finiteMax`: FLT_MAX for Float, 65504 for Half), so a node whose values are all +∞ keeps that
161
+ * start value as its minimum (K7.H1). 0 when empty.
162
+ */
163
+ storedMin(finiteMax) {
164
+ if (this.isEmpty)
165
+ return 0;
166
+ return this.min === Number.POSITIVE_INFINITY ? finiteMax : this.min;
167
+ }
168
+ /** `max` as GridStats stores it: −`finiteMax` when every value is −∞ (see {@link storedMin}). 0 when empty. */
169
+ storedMax(finiteMax) {
170
+ if (this.isEmpty)
171
+ return 0;
172
+ return this.max === Number.NEGATIVE_INFINITY ? -finiteMax : this.max;
173
+ }
102
174
  }
175
+ /** FLT_MAX, `std::numeric_limits<float>::max()`: GridStats' starting minimum for f32 values. */
176
+ export const STATS_FLOAT_MAX = 3.4028234663852886e38;
177
+ /** 65504, the largest finite binary16: GridStats' starting minimum for Half values (raw 0x7BFF). */
178
+ export const STATS_HALF_MAX = 65504;
103
179
  const fround = Math.fround;
104
180
  /** `Vec3<float>::lengthSqr()` evaluated in f32: `x*x + y*y + z*z`, left to right. */
105
181
  export function lengthSqrF32(x, y, z) {
@@ -1 +1 @@
1
- {"version":3,"file":"stats.js","sourceRoot":"","sources":["../../../src/tools/nanovdb/stats.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,MAAM,OAAO,GAAG,CAAC,UAAU,CAAC;AAC5B,MAAM,OAAO,GAAG,UAAU,CAAC;AAE3B;gCACgC;AAChC,MAAM,OAAO,gBAAgB;IAC3B,KAAK,GAAG,CAAC,CAAC;IACF,GAAG,GAAG,CAAC,CAAC;IACR,KAAK,GAAG,CAAC,CAAC;IAClB,GAAG,GAAG,MAAM,CAAC,iBAAiB,CAAC;IAC/B,GAAG,GAAG,MAAM,CAAC,iBAAiB,CAAC;IAC/B,mEAAmE;IACnE,OAAO,GAA6B,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAChE,OAAO,GAA6B,CAAC,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KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/D,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG;YAAE,IAAI,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/D,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;IAEQ,KAAK,CAAC,KAAuB;QACpC,IAAI,KAAK,CAAC,KAAK,KAAK,CAAC;YAAE,OAAO;QAC9B,IAAI,KAAK,YAAY,oBAAoB,EAAE,CAAC;YAC1C,IAAI,KAAK,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG;gBAAE,IAAI,CAAC,MAAM,GAAG,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;YAC1D,IAAI,KAAK,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG;gBAAE,IAAI,CAAC,MAAM,GAAG,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;QAC5D,CAAC;QACD,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;CACF","sourcesContent":["/**\n * stats.ts — per-node active-value statistics, computed the way NanoVDB's\n * `tools/GridStats.h` does: min/max are the extrema of *active* voxel values in\n * a node's subtree, `ave` is their arithmetic mean, and `stddev` is the\n * *population* standard deviation (divide by N, not N-1). A parent node's stats\n * are the exact aggregate of its children's plus its own active tiles, each\n * tile counted with GridStats' weight (see {@link StatsAccumulator.addTile}).\n *\n * The accumulator keeps N, sum and sum-of-squares in f64 so that ave/stddev are\n * computed at full precision before being narrowed to the f32 stored in the\n * grid. These stats feed the material's adaptive stepping (invariant D), so they\n * are computed for real, not stubbed.\n */\n\nconst INT_MIN = -0x80000000;\nconst INT_MAX = 0x7fffffff;\n\n/** Running active-value statistics plus the tight index-space bbox of the\n * active voxels they cover. */\nexport class StatsAccumulator {\n count = 0;\n private sum = 0;\n private sumSq = 0;\n min = Number.POSITIVE_INFINITY;\n max = Number.NEGATIVE_INFINITY;\n // Tight bbox of active voxels (inclusive). Empty when count === 0.\n bboxMin: [number, number, number] = [INT_MAX, INT_MAX, INT_MAX];\n bboxMax: [number, number, number] = [INT_MIN, INT_MIN, INT_MIN];\n\n /** Adds one active voxel at index coord (x,y,z) with the given value. */\n addVoxel(value: number, x: number, y: number, z: number): void {\n this.count += 1;\n this.sum += value;\n this.sumSq += value * value;\n if (value < this.min) this.min = value;\n if (value > this.max) this.max = value;\n if (x < this.bboxMin[0]) this.bboxMin[0] = x;\n if (y < this.bboxMin[1]) this.bboxMin[1] = y;\n if (z < this.bboxMin[2]) this.bboxMin[2] = z;\n if (x > this.bboxMax[0]) this.bboxMax[0] = x;\n if (y > this.bboxMax[1]) this.bboxMax[1] = y;\n if (z > this.bboxMax[2]) this.bboxMax[2] = z;\n }\n\n /**\n * Adds an active tile: `value` counted `weight` times, with the tile's\n * inclusive index bbox. NanoVDB GridStats passes the child node type's slot\n * count as the weight, so once tiles are involved `count` is a stats weight,\n * not a voxel count.\n */\n addTile(\n value: number,\n weight: number,\n bboxMin: readonly [number, number, number],\n bboxMax: readonly [number, number, number],\n ): void {\n this.count += weight;\n this.sum += value * weight;\n this.sumSq += value * value * weight;\n if (value < this.min) this.min = value;\n if (value > this.max) this.max = value;\n for (let a = 0; a < 3; a++) {\n if (bboxMin[a]! < this.bboxMin[a]!) this.bboxMin[a] = bboxMin[a]!;\n if (bboxMax[a]! > this.bboxMax[a]!) this.bboxMax[a] = bboxMax[a]!;\n }\n }\n\n /** Merges a child accumulator's totals into this one. */\n merge(child: StatsAccumulator): void {\n if (child.count === 0) return;\n this.count += child.count;\n this.sum += child.sum;\n this.sumSq += child.sumSq;\n if (child.min < this.min) this.min = child.min;\n if (child.max > this.max) this.max = child.max;\n for (let a = 0; a < 3; a++) {\n if (child.bboxMin[a]! < this.bboxMin[a]!) this.bboxMin[a] = child.bboxMin[a]!;\n if (child.bboxMax[a]! > this.bboxMax[a]!) this.bboxMax[a] = child.bboxMax[a]!;\n }\n }\n\n get average(): number {\n return this.count > 0 ? this.sum / this.count : 0;\n }\n\n /** Population standard deviation (GridStats convention). */\n get stdDev(): number {\n if (this.count === 0) return 0;\n const mean = this.sum / this.count;\n const variance = this.sumSq / this.count - mean * mean;\n return Math.sqrt(Math.max(0, variance));\n }\n\n get isEmpty(): boolean {\n return this.count === 0;\n }\n}\n\nconst fround = Math.fround;\n\n/** `Vec3<float>::lengthSqr()` evaluated in f32: `x*x + y*y + z*z`, left to right. */\nexport function lengthSqrF32(x: number, y: number, z: number): number {\n return fround(fround(fround(x * x) + fround(y * y)) + fround(z * z));\n}\n\n/**\n * Vector statistics, NanoVDB `tools/GridStats.h` `Stats<Vec3f, 1>` (rank 1):\n * every value is ranked by its f32 `lengthSqr()`. `min`/`max` (inherited) are\n * the extreme squared lengths and {@link minVec}/{@link maxVec} the vectors\n * that hold them (first one wins on ties, as `Pair::operator<` is strict);\n * `average` and `stdDev` are the mean and population standard deviation of the\n * squared lengths, not of the components.\n */\nexport class Vec3StatsAccumulator extends StatsAccumulator {\n minVec: [number, number, number] = [0, 0, 0];\n maxVec: [number, number, number] = [0, 0, 0];\n\n /** Adds one active voxel with vector value (vx, vy, vz) at index coord (x, y, z). */\n addVoxelVec(vx: number, vy: number, vz: number, x: number, y: number, z: number): void {\n const s = lengthSqrF32(vx, vy, vz);\n if (s < this.min) this.minVec = [vx, vy, vz];\n if (s > this.max) this.maxVec = [vx, vy, vz];\n this.addVoxel(s, x, y, z);\n }\n\n /** Adds an active vector tile with GridStats weight `weight` (see {@link StatsAccumulator.addTile}). */\n addTileVec(\n value: readonly [number, number, number],\n weight: number,\n bboxMin: readonly [number, number, number],\n bboxMax: readonly [number, number, number],\n ): void {\n const s = lengthSqrF32(value[0], value[1], value[2]);\n if (s < this.min) this.minVec = [value[0], value[1], value[2]];\n if (s > this.max) this.maxVec = [value[0], value[1], value[2]];\n this.addTile(s, weight, bboxMin, bboxMax);\n }\n\n override merge(child: StatsAccumulator): void {\n if (child.count === 0) return;\n if (child instanceof Vec3StatsAccumulator) {\n if (child.min < this.min) this.minVec = [...child.minVec];\n if (child.max > this.max) this.maxVec = [...child.maxVec];\n }\n super.merge(child);\n }\n}\n"]}
1
+ {"version":3,"file":"stats.js","sourceRoot":"","sources":["../../../src/tools/nanovdb/stats.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,MAAM,OAAO,GAAG,CAAC,UAAU,CAAC;AAC5B,MAAM,OAAO,GAAG,UAAU,CAAC;AAK3B,IAAI,YAAY,GAAyB,SAAS,CAAC;AAEnD;;;GAGG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAA0B;IAChE,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,MAAM;QAAE,MAAM,IAAI,UAAU,CAAC,uDAAuD,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACvI,MAAM,QAAQ,GAAG,YAAY,CAAC;IAC9B,YAAY,GAAG,IAAI,CAAC;IACpB,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;gCACgC;AAChC,MAAM,OAAO,gBAAgB;IAC3B,mEAAmE;IACnE,KAAK,GAAG,CAAC,CAAC;IACD,IAAI,GAAyB,YAAY,CAAC;IACnD,SAAS;IACD,GAAG,GAAG,CAAC,CAAC;IACR,KAAK,GAAG,CAAC,CAAC;IAClB,oCAAoC;IAC5B,GAAG,GAAG,CAAC,CAAC;IACR,GAAG,GAAG,CAAC,CAAC;IAChB,GAAG,GAAG,MAAM,CAAC,iBAAiB,CAAC;IAC/B,GAAG,GAAG,MAAM,CAAC,iBAAiB,CAAC;IAC/B,mEAAmE;IACnE,OAAO,GAA6B,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAChE,OAAO,GAA6B,CAAC,OAAO,EA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I,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;IAEQ,KAAK,CAAC,KAAuB;QACpC,IAAI,KAAK,CAAC,KAAK,KAAK,CAAC;YAAE,OAAO;QAC9B,IAAI,KAAK,YAAY,oBAAoB,EAAE,CAAC;YAC1C,IAAI,KAAK,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG;gBAAE,IAAI,CAAC,MAAM,GAAG,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;YAC1D,IAAI,KAAK,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG;gBAAE,IAAI,CAAC,MAAM,GAAG,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;QAC5D,CAAC;QACD,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;CACF","sourcesContent":["/**\n * stats.ts — per-node active-value statistics, computed the way NanoVDB's\n * `tools/GridStats.h` does: min/max are the extrema of *active* voxel values in\n * a node's subtree, `ave` is their arithmetic mean, and `stddev` is the\n * *population* standard deviation (divide by N, not N-1). A parent node's stats\n * are the exact aggregate of its children's plus its own active tiles, each\n * tile counted with GridStats' weight (see {@link StatsAccumulator.addTile}).\n *\n * Two accumulations (K7.H1, DIVERGES V73), chosen by\n * {@link vdbSetStatsAccumulation} when an accumulator is made:\n * - `'welford'` (default since K7.H1): GridStats' own f64 update, ported\n * operation for operation (`Stats<T, 0>::add(val)`, `add(val, n)`,\n * `add(other)`). Fed in GridStats' order (leaf voxels by offset, an internal\n * node's active tiles then its children by slot, the root table in order) it\n * reproduces native ave/stddev bit for bit, ±∞ leaves included (NaN there).\n * - `'sums'` (K1–K7.H): f64 count, sum and sum of squares; ave/stddev within a\n * few f32 ulp of native, ±∞ where Welford gives NaN.\n * Either way ave/stddev are narrowed to f32 only when stored.\n */\n\nconst INT_MIN = -0x80000000;\nconst INT_MAX = 0x7fffffff;\n\n/** How {@link StatsAccumulator} accumulates ave/stddev (K7.H1 A/B; see the file header). */\nexport type VDBStatsAccumulation = \"welford\" | \"sums\";\n\nlet accumulation: VDBStatsAccumulation = \"welford\";\n\n/**\n * Sets how accumulators made from now on compute ave/stddev, and returns the previous setting.\n * Internal (tests and A/B scripts); builds made under one setting are consistent.\n */\nexport function vdbSetStatsAccumulation(mode: VDBStatsAccumulation): VDBStatsAccumulation {\n if (mode !== \"welford\" && mode !== \"sums\") throw new RangeError(`stats accumulation must be 'welford' or 'sums', got ${String(mode)}`);\n const previous = accumulation;\n accumulation = mode;\n return previous;\n}\n\n/** Running active-value statistics plus the tight index-space bbox of the\n * active voxels they cover. */\nexport class StatsAccumulator {\n /** Samples (with tiles: GridStats weight, see {@link addTile}). */\n count = 0;\n readonly mode: VDBStatsAccumulation = accumulation;\n // 'sums'\n private sum = 0;\n private sumSq = 0;\n // 'welford': GridStats' mAvg, mAux.\n private avg = 0;\n private aux = 0;\n min = Number.POSITIVE_INFINITY;\n max = Number.NEGATIVE_INFINITY;\n // Tight bbox of active voxels (inclusive). Empty when count === 0.\n bboxMin: [number, number, number] = [INT_MAX, INT_MAX, INT_MAX];\n bboxMax: [number, number, number] = [INT_MIN, INT_MIN, INT_MIN];\n\n /** Adds one active voxel at index coord (x,y,z) with the given value. */\n addVoxel(value: number, x: number, y: number, z: number): void {\n this.count += 1;\n if (this.mode === \"welford\") {\n // Stats<T, 0>::add(val)\n const delta = value - this.avg;\n this.avg += delta / this.count;\n this.aux += delta * (value - this.avg);\n } else {\n this.sum += value;\n this.sumSq += value * value;\n }\n if (value < this.min) this.min = value;\n if (value > this.max) this.max = value;\n if (x < this.bboxMin[0]) this.bboxMin[0] = x;\n if (y < this.bboxMin[1]) this.bboxMin[1] = y;\n if (z < this.bboxMin[2]) this.bboxMin[2] = z;\n if (x > this.bboxMax[0]) this.bboxMax[0] = x;\n if (y > this.bboxMax[1]) this.bboxMax[1] = y;\n if (z > this.bboxMax[2]) this.bboxMax[2] = z;\n }\n\n /**\n * Adds an active tile: `value` counted `weight` times, with the tile's\n * inclusive index bbox. NanoVDB GridStats passes the child node type's slot\n * count as the weight, so once tiles are involved `count` is a stats weight,\n * not a voxel count.\n */\n addTile(\n value: number,\n weight: number,\n bboxMin: readonly [number, number, number],\n bboxMax: readonly [number, number, number],\n ): void {\n if (this.mode === \"welford\") {\n // Stats<T, 0>::add(val, n), left to right as C++ evaluates it.\n const denom = 1.0 / (this.count + weight);\n const delta = value - this.avg;\n this.avg += denom * delta * weight;\n this.aux += denom * delta * delta * this.count * weight;\n } else {\n this.sum += value * weight;\n this.sumSq += value * value * weight;\n }\n this.count += weight;\n if (value < this.min) this.min = value;\n if (value > this.max) this.max = value;\n for (let a = 0; a < 3; a++) {\n if (bboxMin[a]! < this.bboxMin[a]!) this.bboxMin[a] = bboxMin[a]!;\n if (bboxMax[a]! > this.bboxMax[a]!) this.bboxMax[a] = bboxMax[a]!;\n }\n }\n\n /** Merges a child accumulator's totals into this one (both must use the same accumulation). */\n merge(child: StatsAccumulator): void {\n if (child.count === 0) return;\n if (child.mode !== this.mode) throw new RangeError(\"StatsAccumulator.merge: the accumulators use different accumulations\");\n if (this.mode === \"welford\") {\n // Stats<T, 0>::add(const Stats& other): mAux += other.mAux + (…).\n const denom = 1.0 / (this.count + child.count);\n const delta = child.avg - this.avg;\n this.avg += denom * delta * child.count;\n this.aux += child.aux + denom * delta * delta * this.count * child.count;\n } else {\n this.sum += child.sum;\n this.sumSq += child.sumSq;\n }\n this.count += child.count;\n if (child.min < this.min) this.min = child.min;\n if (child.max > this.max) this.max = child.max;\n for (let a = 0; a < 3; a++) {\n if (child.bboxMin[a]! < this.bboxMin[a]!) this.bboxMin[a] = child.bboxMin[a]!;\n if (child.bboxMax[a]! > this.bboxMax[a]!) this.bboxMax[a] = child.bboxMax[a]!;\n }\n }\n\n get average(): number {\n if (this.mode === \"welford\") return this.avg;\n return this.count > 0 ? this.sum / this.count : 0;\n }\n\n /** Population standard deviation (GridStats convention). */\n get stdDev(): number {\n if (this.mode === \"welford\") return this.count < 2 ? 0 : Math.sqrt(this.aux / this.count);\n if (this.count === 0) return 0;\n const mean = this.sum / this.count;\n const variance = this.sumSq / this.count - mean * mean;\n return Math.sqrt(Math.max(0, variance));\n }\n\n get isEmpty(): boolean {\n return this.count === 0;\n }\n\n /**\n * `min` as GridStats' `Extrema` stores it: Extrema starts at the value type's largest finite value\n * (`finiteMax`: FLT_MAX for Float, 65504 for Half), so a node whose values are all +∞ keeps that\n * start value as its minimum (K7.H1). 0 when empty.\n */\n storedMin(finiteMax: number): number {\n if (this.isEmpty) return 0;\n return this.min === Number.POSITIVE_INFINITY ? finiteMax : this.min;\n }\n\n /** `max` as GridStats stores it: −`finiteMax` when every value is −∞ (see {@link storedMin}). 0 when empty. */\n storedMax(finiteMax: number): number {\n if (this.isEmpty) return 0;\n return this.max === Number.NEGATIVE_INFINITY ? -finiteMax : this.max;\n }\n}\n\n/** FLT_MAX, `std::numeric_limits<float>::max()`: GridStats' starting minimum for f32 values. */\nexport const STATS_FLOAT_MAX = 3.4028234663852886e38;\n/** 65504, the largest finite binary16: GridStats' starting minimum for Half values (raw 0x7BFF). */\nexport const STATS_HALF_MAX = 65504;\n\nconst fround = Math.fround;\n\n/** `Vec3<float>::lengthSqr()` evaluated in f32: `x*x + y*y + z*z`, left to right. */\nexport function lengthSqrF32(x: number, y: number, z: number): number {\n return fround(fround(fround(x * x) + fround(y * y)) + fround(z * z));\n}\n\n/**\n * Vector statistics, NanoVDB `tools/GridStats.h` `Stats<Vec3f, 1>` (rank 1):\n * every value is ranked by its f32 `lengthSqr()`. `min`/`max` (inherited) are\n * the extreme squared lengths and {@link minVec}/{@link maxVec} the vectors\n * that hold them (first one wins on ties, as `Pair::operator<` is strict);\n * `average` and `stdDev` are the mean and population standard deviation of the\n * squared lengths, not of the components.\n */\nexport class Vec3StatsAccumulator extends StatsAccumulator {\n minVec: [number, number, number] = [0, 0, 0];\n maxVec: [number, number, number] = [0, 0, 0];\n\n /** Adds one active voxel with vector value (vx, vy, vz) at index coord (x, y, z). */\n addVoxelVec(vx: number, vy: number, vz: number, x: number, y: number, z: number): void {\n const s = lengthSqrF32(vx, vy, vz);\n if (s < this.min) this.minVec = [vx, vy, vz];\n if (s > this.max) this.maxVec = [vx, vy, vz];\n this.addVoxel(s, x, y, z);\n }\n\n /** Adds an active vector tile with GridStats weight `weight` (see {@link StatsAccumulator.addTile}). */\n addTileVec(\n value: readonly [number, number, number],\n weight: number,\n bboxMin: readonly [number, number, number],\n bboxMax: readonly [number, number, number],\n ): void {\n const s = lengthSqrF32(value[0], value[1], value[2]);\n if (s < this.min) this.minVec = [value[0], value[1], value[2]];\n if (s > this.max) this.maxVec = [value[0], value[1], value[2]];\n this.addTile(s, weight, bboxMin, bboxMax);\n }\n\n override merge(child: StatsAccumulator): void {\n if (child.count === 0) return;\n if (child instanceof Vec3StatsAccumulator) {\n if (child.min < this.min) this.minVec = [...child.minVec];\n if (child.max > this.max) this.maxVec = [...child.maxVec];\n }\n super.merge(child);\n }\n}\n"]}
@@ -17,10 +17,14 @@ export interface VDBTransformSpec {
17
17
  /** New world-space position of index origin (the Map's translation). */
18
18
  worldOrigin: [number, number, number];
19
19
  }
20
+ /** A new transform: a row-major 4x4 matrix (`Float32Array` or `number[16]`), or a {@link VDBTransformSpec}. */
20
21
  export type VDBGridTransformInput = Float32Array | number[] | VDBTransformSpec;
21
22
  /**
22
23
  * Returns a copy of `image` with its transform replaced by an affine uniform
23
24
  * scale + translate. Accepts either a row-major 4x4 matrix (`Float32Array` /
24
25
  * `number[16]`) or an explicit `{ voxelSize, worldOrigin }`.
26
+ *
27
+ * @param image The grid image to copy.
28
+ * @param input The new transform.
25
29
  */
26
30
  export declare function vdbTransform(image: Uint32Array, input: VDBGridTransformInput): Uint32Array;
@@ -16,6 +16,9 @@ import { GRID_OFF_MAP, GRID_OFF_VOXEL_SIZE, GRID_OFF_WORLD_BBOX, GRID_SIZE, MAP_
16
16
  * Returns a copy of `image` with its transform replaced by an affine uniform
17
17
  * scale + translate. Accepts either a row-major 4x4 matrix (`Float32Array` /
18
18
  * `number[16]`) or an explicit `{ voxelSize, worldOrigin }`.
19
+ *
20
+ * @param image The grid image to copy.
21
+ * @param input The new transform.
19
22
  */
20
23
  export function vdbTransform(image, input) {
21
24
  const { voxelSize, translation } = resolve(input);
@@ -1 +1 @@
1
- {"version":3,"file":"transform.js","sourceRoot":"","sources":["../../../src/tools/nanovdb/transform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,mBAAmB,EACnB,SAAS,EACT,eAAe,EACf,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,yBAAyB,GAC1B,MAAM,YAAY,CAAC;AAYpB;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,KAAkB,EAAE,KAA4B;IAC3E,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IAClD,IAAI,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,EAAE,CAAC;QACrB,MAAM,IAAI,aAAa,CAAC,gBAAgB,EAAE,8CAA8C,SAAS,EAAE,CAAC,CAAC;IACvG,CAAC;IAED,MAAM,GAAG,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,sCAAsC;IACjE,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC;IAEtE,QAAQ,CAAC,IAAI,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC;IAEvC,6BAA6B;IAC7B,IAAI,CAAC,UAAU,CAAC,mBAAmB,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;IACt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AE,GAAG,CAAC,CAAC,CAAE,EAAE,IAAI,CAAC,CAAC;QAC5D,IAAI,CAAC,UAAU,CAAC,IAAI,GAAG,eAAe,GAAG,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC,CAAE,EAAE,IAAI,CAAC,CAAC;QAClE,IAAI,CAAC,UAAU,CAAC,IAAI,GAAG,YAAY,GAAG,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,CAAE,EAAE,IAAI,CAAC,CAAC;QAC5D,IAAI,CAAC,UAAU,CAAC,IAAI,GAAG,eAAe,GAAG,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC,CAAE,EAAE,IAAI,CAAC,CAAC;IACpE,CAAC;IACD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,IAAI,CAAC,UAAU,CAAC,IAAI,GAAG,YAAY,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAE,EAAE,IAAI,CAAC,CAAC;QAC1D,IAAI,CAAC,UAAU,CAAC,IAAI,GAAG,YAAY,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAE,EAAE,IAAI,CAAC,CAAC;IAC5D,CAAC;IACD,IAAI,CAAC,UAAU,CAAC,IAAI,GAAG,cAAc,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;IAChD,IAAI,CAAC,UAAU,CAAC,IAAI,GAAG,cAAc,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;AAClD,CAAC","sourcesContent":["/**\n * transform.ts — apply an affine transform to a NanoVDB grid as a metadata-only\n * Map edit (SPEC decision D6). An axis-aligned uniform-scale + translate does not\n * move any voxel between nodes, so the entire tree/leaf region is untouched: we\n * copy the image and rewrite only GridData's `Map` (mat/invMat/vec, both the f32\n * and f64 copies), the `voxelSize` triple and the world-space bbox.\n *\n * v1 handles uniform scale + translate only; a rotation, shear or non-uniform\n * scale throws (those need GPU resampling — the roadmap). The voxel bytes are\n * provably preserved (the tree region is bit-for-bit identical to the source),\n * which the test asserts.\n */\n\nimport { VDBToolsError } from \"../errors.js\";\nimport {\n GRID_OFF_MAP,\n GRID_OFF_VOXEL_SIZE,\n GRID_OFF_WORLD_BBOX,\n GRID_SIZE,\n MAP_OFF_INVMATD,\n MAP_OFF_INVMATF,\n MAP_OFF_MATD,\n MAP_OFF_MATF,\n MAP_OFF_TAPERD,\n MAP_OFF_TAPERF,\n MAP_OFF_VECD,\n MAP_OFF_VECF,\n ROOT_OFF_BBOX_MAX,\n ROOT_OFF_BBOX_MIN,\n TREE_OFF_NODE_OFFSET_ROOT,\n} from \"./bytes.js\";\n\n/** Uniform scale + translate specified directly. */\nexport interface VDBTransformSpec {\n /** New uniform voxel size (world units per voxel). */\n voxelSize: number;\n /** New world-space position of index origin (the Map's translation). */\n worldOrigin: [number, number, number];\n}\n\nexport type VDBGridTransformInput = Float32Array | number[] | VDBTransformSpec;\n\n/**\n * Returns a copy of `image` with its transform replaced by an affine uniform\n * scale + translate. Accepts either a row-major 4x4 matrix (`Float32Array` /\n * `number[16]`) or an explicit `{ voxelSize, worldOrigin }`.\n */\nexport function vdbTransform(image: Uint32Array, input: VDBGridTransformInput): Uint32Array {\n const { voxelSize, translation } = resolve(input);\n if (!(voxelSize > 0)) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", `transform: voxelSize must be positive, got ${voxelSize}`);\n }\n\n const out = image.slice(); // deep copy — source is never mutated\n const view = new DataView(out.buffer, out.byteOffset, out.byteLength);\n\n writeMap(view, voxelSize, translation);\n\n // voxelSize triple (f64[3]).\n view.setFloat64(GRID_OFF_VOXEL_SIZE, voxelSize, true);\n view.setFloat64(GRID_OFF_VOXEL_SIZE + 8, voxelSize, true);\n view.setFloat64(GRID_OFF_VOXEL_SIZE + 16, voxelSize, true);\n\n // World bbox = index bbox mapped through the new transform.\n const rootOff = GRID_SIZE + Number(view.getBigUint64(GRID_SIZE + TREE_OFF_NODE_OFFSET_ROOT, true));\n const imin: [number, number, number] = [\n view.getInt32(rootOff + ROOT_OFF_BBOX_MIN, true),\n view.getInt32(rootOff + ROOT_OFF_BBOX_MIN + 4, true),\n view.getInt32(rootOff + ROOT_OFF_BBOX_MIN + 8, true),\n ];\n const imax: [number, number, number] = [\n view.getInt32(rootOff + ROOT_OFF_BBOX_MAX, true),\n view.getInt32(rootOff + ROOT_OFF_BBOX_MAX + 4, true),\n view.getInt32(rootOff + ROOT_OFF_BBOX_MAX + 8, true),\n ];\n for (let a = 0; a < 3; a++) {\n view.setFloat64(GRID_OFF_WORLD_BBOX + a * 8, imin[a]! * voxelSize + translation[a]!, true);\n // \"+ one voxel\" convention: the world max corner is (indexMax + 1) * voxelSize.\n view.setFloat64(GRID_OFF_WORLD_BBOX + 24 + a * 8, (imax[a]! + 1) * voxelSize + translation[a]!, true);\n }\n\n return out;\n}\n\nfunction resolve(input: VDBGridTransformInput): { voxelSize: number; translation: [number, number, number] } {\n if (input instanceof Float32Array || Array.isArray(input)) {\n const m = input;\n if (m.length !== 16) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", `transform: expected a 4x4 (16-element) matrix, got ${m.length}`);\n }\n const sx = m[0]!;\n const sy = m[5]!;\n const sz = m[10]!;\n const offDiagonal = [m[1]!, m[2]!, m[4]!, m[6]!, m[8]!, m[9]!];\n const eps = 1e-6 * Math.max(1, Math.abs(sx), Math.abs(sy), Math.abs(sz));\n const rotated = offDiagonal.some((v) => Math.abs(v) > eps);\n const nonUniform = Math.abs(sx - sy) > eps || Math.abs(sx - sz) > eps;\n if (rotated || nonUniform) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", \n `transform: matrix is ${rotated ? \"rotated/sheared\" : \"non-uniformly scaled\"} ` +\n `(scale [${sx}, ${sy}, ${sz}]). v1 supports uniform scale + translate only; ` +\n `rotation/shear/anisotropy need GPU resampling (roadmap).`,\n );\n }\n return { voxelSize: sx, translation: [m[3]!, m[7]!, m[11]!] };\n }\n return { voxelSize: input.voxelSize, translation: [...input.worldOrigin] };\n}\n\nfunction writeMap(view: DataView, s: number, t: [number, number, number]): void {\n const inv = 1 / s;\n const mat = [s, 0, 0, 0, s, 0, 0, 0, s];\n const invMat = [inv, 0, 0, 0, inv, 0, 0, 0, inv];\n const base = GRID_OFF_MAP;\n for (let i = 0; i < 9; i++) {\n view.setFloat32(base + MAP_OFF_MATF + i * 4, mat[i]!, true);\n view.setFloat32(base + MAP_OFF_INVMATF + i * 4, invMat[i]!, true);\n view.setFloat64(base + MAP_OFF_MATD + i * 8, mat[i]!, true);\n view.setFloat64(base + MAP_OFF_INVMATD + i * 8, invMat[i]!, true);\n }\n for (let i = 0; i < 3; i++) {\n view.setFloat32(base + MAP_OFF_VECF + i * 4, t[i]!, true);\n view.setFloat64(base + MAP_OFF_VECD + i * 8, t[i]!, true);\n }\n view.setFloat32(base + MAP_OFF_TAPERF, 1, true);\n view.setFloat64(base + MAP_OFF_TAPERD, 1, true);\n}\n"]}
1
+ {"version":3,"file":"transform.js","sourceRoot":"","sources":["../../../src/tools/nanovdb/transform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,mBAAmB,EACnB,SAAS,EACT,eAAe,EACf,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,yBAAyB,GAC1B,MAAM,YAAY,CAAC;AAapB;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAAC,KAAkB,EAAE,KAA4B;IAC3E,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IAClD,IAAI,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,EAAE,CAAC;QACrB,MAAM,IAAI,aAAa,CA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U,CAAC,IAAI,GAAG,cAAc,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;IAChD,IAAI,CAAC,UAAU,CAAC,IAAI,GAAG,cAAc,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;AAClD,CAAC","sourcesContent":["/**\n * transform.ts — apply an affine transform to a NanoVDB grid as a metadata-only\n * Map edit (SPEC decision D6). An axis-aligned uniform-scale + translate does not\n * move any voxel between nodes, so the entire tree/leaf region is untouched: we\n * copy the image and rewrite only GridData's `Map` (mat/invMat/vec, both the f32\n * and f64 copies), the `voxelSize` triple and the world-space bbox.\n *\n * v1 handles uniform scale + translate only; a rotation, shear or non-uniform\n * scale throws (those need GPU resampling — the roadmap). The voxel bytes are\n * provably preserved (the tree region is bit-for-bit identical to the source),\n * which the test asserts.\n */\n\nimport { VDBToolsError } from \"../errors.js\";\nimport {\n GRID_OFF_MAP,\n GRID_OFF_VOXEL_SIZE,\n GRID_OFF_WORLD_BBOX,\n GRID_SIZE,\n MAP_OFF_INVMATD,\n MAP_OFF_INVMATF,\n MAP_OFF_MATD,\n MAP_OFF_MATF,\n MAP_OFF_TAPERD,\n MAP_OFF_TAPERF,\n MAP_OFF_VECD,\n MAP_OFF_VECF,\n ROOT_OFF_BBOX_MAX,\n ROOT_OFF_BBOX_MIN,\n TREE_OFF_NODE_OFFSET_ROOT,\n} from \"./bytes.js\";\n\n/** Uniform scale + translate specified directly. */\nexport interface VDBTransformSpec {\n /** New uniform voxel size (world units per voxel). */\n voxelSize: number;\n /** New world-space position of index origin (the Map's translation). */\n worldOrigin: [number, number, number];\n}\n\n/** A new transform: a row-major 4x4 matrix (`Float32Array` or `number[16]`), or a {@link VDBTransformSpec}. */\nexport type VDBGridTransformInput = Float32Array | number[] | VDBTransformSpec;\n\n/**\n * Returns a copy of `image` with its transform replaced by an affine uniform\n * scale + translate. Accepts either a row-major 4x4 matrix (`Float32Array` /\n * `number[16]`) or an explicit `{ voxelSize, worldOrigin }`.\n *\n * @param image The grid image to copy.\n * @param input The new transform.\n */\nexport function vdbTransform(image: Uint32Array, input: VDBGridTransformInput): Uint32Array {\n const { voxelSize, translation } = resolve(input);\n if (!(voxelSize > 0)) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", `transform: voxelSize must be positive, got ${voxelSize}`);\n }\n\n const out = image.slice(); // deep copy — source is never mutated\n const view = new DataView(out.buffer, out.byteOffset, out.byteLength);\n\n writeMap(view, voxelSize, translation);\n\n // voxelSize triple (f64[3]).\n view.setFloat64(GRID_OFF_VOXEL_SIZE, voxelSize, true);\n view.setFloat64(GRID_OFF_VOXEL_SIZE + 8, voxelSize, true);\n view.setFloat64(GRID_OFF_VOXEL_SIZE + 16, voxelSize, true);\n\n // World bbox = index bbox mapped through the new transform.\n const rootOff = GRID_SIZE + Number(view.getBigUint64(GRID_SIZE + TREE_OFF_NODE_OFFSET_ROOT, true));\n const imin: [number, number, number] = [\n view.getInt32(rootOff + ROOT_OFF_BBOX_MIN, true),\n view.getInt32(rootOff + ROOT_OFF_BBOX_MIN + 4, true),\n view.getInt32(rootOff + ROOT_OFF_BBOX_MIN + 8, true),\n ];\n const imax: [number, number, number] = [\n view.getInt32(rootOff + ROOT_OFF_BBOX_MAX, true),\n view.getInt32(rootOff + ROOT_OFF_BBOX_MAX + 4, true),\n view.getInt32(rootOff + ROOT_OFF_BBOX_MAX + 8, true),\n ];\n for (let a = 0; a < 3; a++) {\n view.setFloat64(GRID_OFF_WORLD_BBOX + a * 8, imin[a]! * voxelSize + translation[a]!, true);\n // \"+ one voxel\" convention: the world max corner is (indexMax + 1) * voxelSize.\n view.setFloat64(GRID_OFF_WORLD_BBOX + 24 + a * 8, (imax[a]! + 1) * voxelSize + translation[a]!, true);\n }\n\n return out;\n}\n\nfunction resolve(input: VDBGridTransformInput): { voxelSize: number; translation: [number, number, number] } {\n if (input instanceof Float32Array || Array.isArray(input)) {\n const m = input;\n if (m.length !== 16) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", `transform: expected a 4x4 (16-element) matrix, got ${m.length}`);\n }\n const sx = m[0]!;\n const sy = m[5]!;\n const sz = m[10]!;\n const offDiagonal = [m[1]!, m[2]!, m[4]!, m[6]!, m[8]!, m[9]!];\n const eps = 1e-6 * Math.max(1, Math.abs(sx), Math.abs(sy), Math.abs(sz));\n const rotated = offDiagonal.some((v) => Math.abs(v) > eps);\n const nonUniform = Math.abs(sx - sy) > eps || Math.abs(sx - sz) > eps;\n if (rotated || nonUniform) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", \n `transform: matrix is ${rotated ? \"rotated/sheared\" : \"non-uniformly scaled\"} ` +\n `(scale [${sx}, ${sy}, ${sz}]). v1 supports uniform scale + translate only; ` +\n `rotation/shear/anisotropy need GPU resampling (roadmap).`,\n );\n }\n return { voxelSize: sx, translation: [m[3]!, m[7]!, m[11]!] };\n }\n return { voxelSize: input.voxelSize, translation: [...input.worldOrigin] };\n}\n\nfunction writeMap(view: DataView, s: number, t: [number, number, number]): void {\n const inv = 1 / s;\n const mat = [s, 0, 0, 0, s, 0, 0, 0, s];\n const invMat = [inv, 0, 0, 0, inv, 0, 0, 0, inv];\n const base = GRID_OFF_MAP;\n for (let i = 0; i < 9; i++) {\n view.setFloat32(base + MAP_OFF_MATF + i * 4, mat[i]!, true);\n view.setFloat32(base + MAP_OFF_INVMATF + i * 4, invMat[i]!, true);\n view.setFloat64(base + MAP_OFF_MATD + i * 8, mat[i]!, true);\n view.setFloat64(base + MAP_OFF_INVMATD + i * 8, invMat[i]!, true);\n }\n for (let i = 0; i < 3; i++) {\n view.setFloat32(base + MAP_OFF_VECF + i * 4, t[i]!, true);\n view.setFloat64(base + MAP_OFF_VECD + i * 8, t[i]!, true);\n }\n view.setFloat32(base + MAP_OFF_TAPERF, 1, true);\n view.setFloat64(base + MAP_OFF_TAPERD, 1, true);\n}\n"]}