@pmndrs/vdb 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (570) hide show
  1. package/CHANGELOG.md +727 -0
  2. package/LICENSE +21 -0
  3. package/README.md +496 -2
  4. package/THIRD_PARTY_NOTICES.md +315 -0
  5. package/dist/core/compute/atlas.d.ts +102 -0
  6. package/dist/core/compute/atlas.js +103 -0
  7. package/dist/core/compute/atlas.js.map +1 -0
  8. package/dist/core/compute/index.d.ts +13 -0
  9. package/dist/core/compute/index.js +9 -0
  10. package/dist/core/compute/index.js.map +1 -0
  11. package/dist/core/compute/majorant-build.d.ts +45 -0
  12. package/dist/core/compute/majorant-build.js +193 -0
  13. package/dist/core/compute/majorant-build.js.map +1 -0
  14. package/dist/core/compute/multi-scale.d.ts +155 -0
  15. package/dist/core/compute/multi-scale.js +684 -0
  16. package/dist/core/compute/multi-scale.js.map +1 -0
  17. package/dist/core/compute/pyramid.d.ts +120 -0
  18. package/dist/core/compute/pyramid.js +468 -0
  19. package/dist/core/compute/pyramid.js.map +1 -0
  20. package/dist/core/compute/shared.d.ts +116 -0
  21. package/dist/core/compute/shared.js +211 -0
  22. package/dist/core/compute/shared.js.map +1 -0
  23. package/dist/core/compute/stats.d.ts +78 -0
  24. package/dist/core/compute/stats.js +193 -0
  25. package/dist/core/compute/stats.js.map +1 -0
  26. package/dist/core/compute/value-transform.d.ts +30 -0
  27. package/dist/core/compute/value-transform.js +64 -0
  28. package/dist/core/compute/value-transform.js.map +1 -0
  29. package/dist/core/errors.d.ts +21 -0
  30. package/dist/core/errors.js +17 -0
  31. package/dist/core/errors.js.map +1 -0
  32. package/dist/core/frame/emission.d.ts +85 -0
  33. package/dist/core/frame/emission.js +422 -0
  34. package/dist/core/frame/emission.js.map +1 -0
  35. package/dist/core/frame/environment.d.ts +47 -0
  36. package/dist/core/frame/environment.js +178 -0
  37. package/dist/core/frame/environment.js.map +1 -0
  38. package/dist/core/frame/index.d.ts +39 -0
  39. package/dist/core/frame/index.js +27 -0
  40. package/dist/core/frame/index.js.map +1 -0
  41. package/dist/core/frame/kernels.d.ts +115 -0
  42. package/dist/core/frame/kernels.js +496 -0
  43. package/dist/core/frame/kernels.js.map +1 -0
  44. package/dist/core/frame/limits.d.ts +67 -0
  45. package/dist/core/frame/limits.js +109 -0
  46. package/dist/core/frame/limits.js.map +1 -0
  47. package/dist/core/frame/phase.d.ts +17 -0
  48. package/dist/core/frame/phase.js +53 -0
  49. package/dist/core/frame/phase.js.map +1 -0
  50. package/dist/core/frame/pipelines.d.ts +49 -0
  51. package/dist/core/frame/pipelines.js +147 -0
  52. package/dist/core/frame/pipelines.js.map +1 -0
  53. package/dist/core/frame/renderer.d.ts +122 -0
  54. package/dist/core/frame/renderer.js +1712 -0
  55. package/dist/core/frame/renderer.js.map +1 -0
  56. package/dist/core/frame/resources.d.ts +71 -0
  57. package/dist/core/frame/resources.js +100 -0
  58. package/dist/core/frame/resources.js.map +1 -0
  59. package/dist/core/frame/scattering.d.ts +97 -0
  60. package/dist/core/frame/scattering.js +332 -0
  61. package/dist/core/frame/scattering.js.map +1 -0
  62. package/dist/core/frame/settings.d.ts +243 -0
  63. package/dist/core/frame/settings.js +67 -0
  64. package/dist/core/frame/settings.js.map +1 -0
  65. package/dist/core/frame/shadows.d.ts +55 -0
  66. package/dist/core/frame/shadows.js +460 -0
  67. package/dist/core/frame/shadows.js.map +1 -0
  68. package/dist/core/frame/types.d.ts +415 -0
  69. package/dist/core/frame/types.js +49 -0
  70. package/dist/core/frame/types.js.map +1 -0
  71. package/dist/core/frame/uniforms.d.ts +105 -0
  72. package/dist/core/frame/uniforms.js +276 -0
  73. package/dist/core/frame/uniforms.js.map +1 -0
  74. package/dist/core/frame/wgsl/chunks.d.ts +4 -0
  75. package/dist/core/frame/wgsl/chunks.js +728 -0
  76. package/dist/core/frame/wgsl/chunks.js.map +1 -0
  77. package/dist/core/frame/wgsl/emission.d.ts +82 -0
  78. package/dist/core/frame/wgsl/emission.js +353 -0
  79. package/dist/core/frame/wgsl/emission.js.map +1 -0
  80. package/dist/core/frame/wgsl/environment.d.ts +42 -0
  81. package/dist/core/frame/wgsl/environment.js +711 -0
  82. package/dist/core/frame/wgsl/environment.js.map +1 -0
  83. package/dist/core/frame/wgsl/gather.d.ts +55 -0
  84. package/dist/core/frame/wgsl/gather.js +850 -0
  85. package/dist/core/frame/wgsl/gather.js.map +1 -0
  86. package/dist/core/frame/wgsl/integrate.d.ts +78 -0
  87. package/dist/core/frame/wgsl/integrate.js +213 -0
  88. package/dist/core/frame/wgsl/integrate.js.map +1 -0
  89. package/dist/core/frame/wgsl/lighting.d.ts +103 -0
  90. package/dist/core/frame/wgsl/lighting.js +1636 -0
  91. package/dist/core/frame/wgsl/lighting.js.map +1 -0
  92. package/dist/core/frame/wgsl/occluders.d.ts +20 -0
  93. package/dist/core/frame/wgsl/occluders.js +95 -0
  94. package/dist/core/frame/wgsl/occluders.js.map +1 -0
  95. package/dist/core/frame/wgsl/resolve.d.ts +19 -0
  96. package/dist/core/frame/wgsl/resolve.js +205 -0
  97. package/dist/core/frame/wgsl/resolve.js.map +1 -0
  98. package/dist/core/frame/wgsl/shadows.d.ts +35 -0
  99. package/dist/core/frame/wgsl/shadows.js +328 -0
  100. package/dist/core/frame/wgsl/shadows.js.map +1 -0
  101. package/dist/core/half.d.ts +11 -0
  102. package/dist/core/half.js +22 -0
  103. package/dist/core/half.js.map +1 -0
  104. package/dist/core/index.d.ts +52 -0
  105. package/dist/core/index.js +46 -0
  106. package/dist/core/index.js.map +1 -0
  107. package/dist/core/internal.d.ts +31 -0
  108. package/dist/core/internal.js +32 -0
  109. package/dist/core/internal.js.map +1 -0
  110. package/dist/core/pool/affine.d.ts +34 -0
  111. package/dist/core/pool/affine.js +100 -0
  112. package/dist/core/pool/affine.js.map +1 -0
  113. package/dist/core/pool/allocator.d.ts +32 -0
  114. package/dist/core/pool/allocator.js +81 -0
  115. package/dist/core/pool/allocator.js.map +1 -0
  116. package/dist/core/pool/image-header.d.ts +93 -0
  117. package/dist/core/pool/image-header.js +194 -0
  118. package/dist/core/pool/image-header.js.map +1 -0
  119. package/dist/core/pool/layout.d.ts +198 -0
  120. package/dist/core/pool/layout.js +316 -0
  121. package/dist/core/pool/layout.js.map +1 -0
  122. package/dist/core/pool/limits.d.ts +41 -0
  123. package/dist/core/pool/limits.js +80 -0
  124. package/dist/core/pool/limits.js.map +1 -0
  125. package/dist/core/pool/pool.d.ts +384 -0
  126. package/dist/core/pool/pool.js +1184 -0
  127. package/dist/core/pool/pool.js.map +1 -0
  128. package/dist/core/reference/index.d.ts +6 -0
  129. package/dist/core/reference/index.js +7 -0
  130. package/dist/core/reference/index.js.map +1 -0
  131. package/dist/core/reference/renderer.d.ts +105 -0
  132. package/dist/core/reference/renderer.js +474 -0
  133. package/dist/core/reference/renderer.js.map +1 -0
  134. package/dist/core/reference/wgsl.d.ts +65 -0
  135. package/dist/core/reference/wgsl.js +803 -0
  136. package/dist/core/reference/wgsl.js.map +1 -0
  137. package/dist/core/sequence.d.ts +347 -0
  138. package/dist/core/sequence.js +548 -0
  139. package/dist/core/sequence.js.map +1 -0
  140. package/dist/core/source/brick-cache.d.ts +165 -0
  141. package/dist/core/source/brick-cache.js +627 -0
  142. package/dist/core/source/brick-cache.js.map +1 -0
  143. package/dist/core/source/dense-fill.d.ts +53 -0
  144. package/dist/core/source/dense-fill.js +377 -0
  145. package/dist/core/source/dense-fill.js.map +1 -0
  146. package/dist/core/source/dense.d.ts +50 -0
  147. package/dist/core/source/dense.js +384 -0
  148. package/dist/core/source/dense.js.map +1 -0
  149. package/dist/core/source/sparse-wgsl.d.ts +92 -0
  150. package/dist/core/source/sparse-wgsl.js +481 -0
  151. package/dist/core/source/sparse-wgsl.js.map +1 -0
  152. package/dist/core/source/sparse.d.ts +192 -0
  153. package/dist/core/source/sparse.js +762 -0
  154. package/dist/core/source/sparse.js.map +1 -0
  155. package/dist/core/source/types.d.ts +120 -0
  156. package/dist/core/source/types.js +9 -0
  157. package/dist/core/source/types.js.map +1 -0
  158. package/dist/core/surface/index.d.ts +10 -0
  159. package/dist/core/surface/index.js +9 -0
  160. package/dist/core/surface/index.js.map +1 -0
  161. package/dist/core/surface/level-set-pass.d.ts +140 -0
  162. package/dist/core/surface/level-set-pass.js +291 -0
  163. package/dist/core/surface/level-set-pass.js.map +1 -0
  164. package/dist/core/surface/level-set-wgsl.d.ts +46 -0
  165. package/dist/core/surface/level-set-wgsl.js +99 -0
  166. package/dist/core/surface/level-set-wgsl.js.map +1 -0
  167. package/dist/core/surface/points.d.ts +109 -0
  168. package/dist/core/surface/points.js +226 -0
  169. package/dist/core/surface/points.js.map +1 -0
  170. package/dist/core/types.d.ts +37 -0
  171. package/dist/core/types.js +32 -0
  172. package/dist/core/types.js.map +1 -0
  173. package/dist/core/wgsl/api.d.ts +65 -0
  174. package/dist/core/wgsl/api.js +546 -0
  175. package/dist/core/wgsl/api.js.map +1 -0
  176. package/dist/core/wgsl/generate.d.ts +90 -0
  177. package/dist/core/wgsl/generate.js +678 -0
  178. package/dist/core/wgsl/generate.js.map +1 -0
  179. package/dist/core/wgsl/lean.d.ts +50 -0
  180. package/dist/core/wgsl/lean.js +327 -0
  181. package/dist/core/wgsl/lean.js.map +1 -0
  182. package/dist/core/wgsl/level-set.d.ts +58 -0
  183. package/dist/core/wgsl/level-set.js +200 -0
  184. package/dist/core/wgsl/level-set.js.map +1 -0
  185. package/dist/core/wgsl/majorant.d.ts +62 -0
  186. package/dist/core/wgsl/majorant.js +381 -0
  187. package/dist/core/wgsl/majorant.js.map +1 -0
  188. package/dist/core/wgsl/pnanovdb.chunks.generated.d.ts +14 -0
  189. package/dist/core/wgsl/pnanovdb.chunks.generated.js +333 -0
  190. package/dist/core/wgsl/pnanovdb.chunks.generated.js.map +1 -0
  191. package/dist/core/wgsl/reserved.d.ts +9 -0
  192. package/dist/core/wgsl/reserved.js +26 -0
  193. package/dist/core/wgsl/reserved.js.map +1 -0
  194. package/dist/core/wgsl/types.d.ts +198 -0
  195. package/dist/core/wgsl/types.js +2 -0
  196. package/dist/core/wgsl/types.js.map +1 -0
  197. package/dist/three/coarse-first.d.ts +207 -0
  198. package/dist/three/coarse-first.js +205 -0
  199. package/dist/three/coarse-first.js.map +1 -0
  200. package/dist/three/compute.d.ts +73 -0
  201. package/dist/three/compute.js +66 -0
  202. package/dist/three/compute.js.map +1 -0
  203. package/dist/three/device.d.ts +66 -0
  204. package/dist/three/device.js +62 -0
  205. package/dist/three/device.js.map +1 -0
  206. package/dist/three/frame/core-environment.d.ts +38 -0
  207. package/dist/three/frame/core-environment.js +154 -0
  208. package/dist/three/frame/core-environment.js.map +1 -0
  209. package/dist/three/frame/core-integrate-material.d.ts +34 -0
  210. package/dist/three/frame/core-integrate-material.js +162 -0
  211. package/dist/three/frame/core-integrate-material.js.map +1 -0
  212. package/dist/three/frame/core-occluders.d.ts +53 -0
  213. package/dist/three/frame/core-occluders.js +193 -0
  214. package/dist/three/frame/core-occluders.js.map +1 -0
  215. package/dist/three/frame/core-structs.d.ts +34 -0
  216. package/dist/three/frame/core-structs.js +61 -0
  217. package/dist/three/frame/core-structs.js.map +1 -0
  218. package/dist/three/frame/core-textures.d.ts +41 -0
  219. package/dist/three/frame/core-textures.js +114 -0
  220. package/dist/three/frame/core-textures.js.map +1 -0
  221. package/dist/three/frame/emission-light.d.ts +117 -0
  222. package/dist/three/frame/emission-light.js +276 -0
  223. package/dist/three/frame/emission-light.js.map +1 -0
  224. package/dist/three/frame/index.d.ts +19 -0
  225. package/dist/three/frame/index.js +15 -0
  226. package/dist/three/frame/index.js.map +1 -0
  227. package/dist/three/frame/medium.d.ts +33 -0
  228. package/dist/three/frame/medium.js +29 -0
  229. package/dist/three/frame/medium.js.map +1 -0
  230. package/dist/three/frame/renderer.d.ts +97 -0
  231. package/dist/three/frame/renderer.js +480 -0
  232. package/dist/three/frame/renderer.js.map +1 -0
  233. package/dist/three/frame/spectrum.d.ts +4 -0
  234. package/dist/three/frame/spectrum.js +15 -0
  235. package/dist/three/frame/spectrum.js.map +1 -0
  236. package/dist/three/frame/three-internals.d.ts +60 -0
  237. package/dist/three/frame/three-internals.js +152 -0
  238. package/dist/three/frame/three-internals.js.map +1 -0
  239. package/dist/three/frame/volume-shadows.d.ts +139 -0
  240. package/dist/three/frame/volume-shadows.js +403 -0
  241. package/dist/three/frame/volume-shadows.js.map +1 -0
  242. package/dist/three/frame/volume.d.ts +230 -0
  243. package/dist/three/frame/volume.js +268 -0
  244. package/dist/three/frame/volume.js.map +1 -0
  245. package/dist/three/grid-node.d.ts +229 -0
  246. package/dist/three/grid-node.js +545 -0
  247. package/dist/three/grid-node.js.map +1 -0
  248. package/dist/three/index.d.ts +52 -0
  249. package/dist/three/index.js +58 -0
  250. package/dist/three/index.js.map +1 -0
  251. package/dist/three/internal.d.ts +20 -0
  252. package/dist/three/internal.js +18 -0
  253. package/dist/three/internal.js.map +1 -0
  254. package/dist/three/level-set-material.d.ts +185 -0
  255. package/dist/three/level-set-material.js +241 -0
  256. package/dist/three/level-set-material.js.map +1 -0
  257. package/dist/three/level-set-physical-material.d.ts +154 -0
  258. package/dist/three/level-set-physical-material.js +253 -0
  259. package/dist/three/level-set-physical-material.js.map +1 -0
  260. package/dist/three/level-set-velocity.d.ts +94 -0
  261. package/dist/three/level-set-velocity.js +208 -0
  262. package/dist/three/level-set-velocity.js.map +1 -0
  263. package/dist/three/material.d.ts +324 -0
  264. package/dist/three/material.js +502 -0
  265. package/dist/three/material.js.map +1 -0
  266. package/dist/three/points.d.ts +140 -0
  267. package/dist/three/points.js +261 -0
  268. package/dist/three/points.js.map +1 -0
  269. package/dist/three/sparse-source.d.ts +165 -0
  270. package/dist/three/sparse-source.js +405 -0
  271. package/dist/three/sparse-source.js.map +1 -0
  272. package/dist/three/volume-source.d.ts +22 -0
  273. package/dist/three/volume-source.js +110 -0
  274. package/dist/three/volume-source.js.map +1 -0
  275. package/dist/tools/cpu/brick-atlas.d.ts +36 -0
  276. package/dist/tools/cpu/brick-atlas.js +129 -0
  277. package/dist/tools/cpu/brick-atlas.js.map +1 -0
  278. package/dist/tools/cpu/compute.d.ts +116 -0
  279. package/dist/tools/cpu/compute.js +239 -0
  280. package/dist/tools/cpu/compute.js.map +1 -0
  281. package/dist/tools/cpu/lean-reads.d.ts +81 -0
  282. package/dist/tools/cpu/lean-reads.js +262 -0
  283. package/dist/tools/cpu/lean-reads.js.map +1 -0
  284. package/dist/tools/cpu/level-set.d.ts +111 -0
  285. package/dist/tools/cpu/level-set.js +313 -0
  286. package/dist/tools/cpu/level-set.js.map +1 -0
  287. package/dist/tools/cpu/majorant.d.ts +265 -0
  288. package/dist/tools/cpu/majorant.js +541 -0
  289. package/dist/tools/cpu/majorant.js.map +1 -0
  290. package/dist/tools/cpu/march.d.ts +297 -0
  291. package/dist/tools/cpu/march.js +726 -0
  292. package/dist/tools/cpu/march.js.map +1 -0
  293. package/dist/tools/cpu/mesh-decimate.d.ts +124 -0
  294. package/dist/tools/cpu/mesh-decimate.js +1225 -0
  295. package/dist/tools/cpu/mesh-decimate.js.map +1 -0
  296. package/dist/tools/cpu/points.d.ts +29 -0
  297. package/dist/tools/cpu/points.js +38 -0
  298. package/dist/tools/cpu/points.js.map +1 -0
  299. package/dist/tools/cpu/probe-coords.d.ts +70 -0
  300. package/dist/tools/cpu/probe-coords.js +116 -0
  301. package/dist/tools/cpu/probe-coords.js.map +1 -0
  302. package/dist/tools/cpu/read-value.d.ts +44 -0
  303. package/dist/tools/cpu/read-value.js +351 -0
  304. package/dist/tools/cpu/read-value.js.map +1 -0
  305. package/dist/tools/cpu/sample-trilinear.d.ts +43 -0
  306. package/dist/tools/cpu/sample-trilinear.js +168 -0
  307. package/dist/tools/cpu/sample-trilinear.js.map +1 -0
  308. package/dist/tools/cpu/stride-tables.d.ts +56 -0
  309. package/dist/tools/cpu/stride-tables.generated.d.ts +1059 -0
  310. package/dist/tools/cpu/stride-tables.generated.js +1267 -0
  311. package/dist/tools/cpu/stride-tables.generated.js.map +1 -0
  312. package/dist/tools/cpu/stride-tables.js +78 -0
  313. package/dist/tools/cpu/stride-tables.js.map +1 -0
  314. package/dist/tools/cpu/surface-nets.d.ts +90 -0
  315. package/dist/tools/cpu/surface-nets.js +597 -0
  316. package/dist/tools/cpu/surface-nets.js.map +1 -0
  317. package/dist/tools/errors.d.ts +66 -0
  318. package/dist/tools/errors.js +67 -0
  319. package/dist/tools/errors.js.map +1 -0
  320. package/dist/tools/frame/ambient.d.ts +98 -0
  321. package/dist/tools/frame/ambient.js +274 -0
  322. package/dist/tools/frame/ambient.js.map +1 -0
  323. package/dist/tools/frame/blackbody.d.ts +57 -0
  324. package/dist/tools/frame/blackbody.js +151 -0
  325. package/dist/tools/frame/blackbody.js.map +1 -0
  326. package/dist/tools/frame/brick-cache.d.ts +165 -0
  327. package/dist/tools/frame/brick-cache.js +326 -0
  328. package/dist/tools/frame/brick-cache.js.map +1 -0
  329. package/dist/tools/frame/emission.d.ts +137 -0
  330. package/dist/tools/frame/emission.js +290 -0
  331. package/dist/tools/frame/emission.js.map +1 -0
  332. package/dist/tools/frame/environment-gpu.d.ts +111 -0
  333. package/dist/tools/frame/environment-gpu.js +280 -0
  334. package/dist/tools/frame/environment-gpu.js.map +1 -0
  335. package/dist/tools/frame/environment.d.ts +106 -0
  336. package/dist/tools/frame/environment.js +272 -0
  337. package/dist/tools/frame/environment.js.map +1 -0
  338. package/dist/tools/frame/froxel.d.ts +58 -0
  339. package/dist/tools/frame/froxel.js +115 -0
  340. package/dist/tools/frame/froxel.js.map +1 -0
  341. package/dist/tools/frame/grid.d.ts +392 -0
  342. package/dist/tools/frame/grid.js +802 -0
  343. package/dist/tools/frame/grid.js.map +1 -0
  344. package/dist/tools/frame/index.d.ts +150 -0
  345. package/dist/tools/frame/index.js +389 -0
  346. package/dist/tools/frame/index.js.map +1 -0
  347. package/dist/tools/frame/medium.d.ts +77 -0
  348. package/dist/tools/frame/medium.js +101 -0
  349. package/dist/tools/frame/medium.js.map +1 -0
  350. package/dist/tools/frame/mie-table.d.ts +6 -0
  351. package/dist/tools/frame/mie-table.js +16 -0
  352. package/dist/tools/frame/mie-table.js.map +1 -0
  353. package/dist/tools/frame/mie.d.ts +63 -0
  354. package/dist/tools/frame/mie.js +194 -0
  355. package/dist/tools/frame/mie.js.map +1 -0
  356. package/dist/tools/frame/mlp-nn.d.ts +36 -0
  357. package/dist/tools/frame/mlp-nn.js +159 -0
  358. package/dist/tools/frame/mlp-nn.js.map +1 -0
  359. package/dist/tools/frame/mlp-tza.d.ts +29 -0
  360. package/dist/tools/frame/mlp-tza.js +186 -0
  361. package/dist/tools/frame/mlp-tza.js.map +1 -0
  362. package/dist/tools/frame/mlp.d.ts +183 -0
  363. package/dist/tools/frame/mlp.js +434 -0
  364. package/dist/tools/frame/mlp.js.map +1 -0
  365. package/dist/tools/frame/ms-exit.d.ts +42 -0
  366. package/dist/tools/frame/ms-exit.js +90 -0
  367. package/dist/tools/frame/ms-exit.js.map +1 -0
  368. package/dist/tools/frame/multi-scale.d.ts +152 -0
  369. package/dist/tools/frame/multi-scale.js +302 -0
  370. package/dist/tools/frame/multi-scale.js.map +1 -0
  371. package/dist/tools/frame/neural-weights.d.ts +10 -0
  372. package/dist/tools/frame/neural-weights.js +244 -0
  373. package/dist/tools/frame/neural-weights.js.map +1 -0
  374. package/dist/tools/frame/neural.d.ts +80 -0
  375. package/dist/tools/frame/neural.js +150 -0
  376. package/dist/tools/frame/neural.js.map +1 -0
  377. package/dist/tools/frame/occluders.d.ts +51 -0
  378. package/dist/tools/frame/occluders.js +72 -0
  379. package/dist/tools/frame/occluders.js.map +1 -0
  380. package/dist/tools/frame/pyramid-layout.d.ts +55 -0
  381. package/dist/tools/frame/pyramid-layout.js +100 -0
  382. package/dist/tools/frame/pyramid-layout.js.map +1 -0
  383. package/dist/tools/frame/shadows.d.ts +190 -0
  384. package/dist/tools/frame/shadows.js +468 -0
  385. package/dist/tools/frame/shadows.js.map +1 -0
  386. package/dist/tools/frame/sparse.d.ts +147 -0
  387. package/dist/tools/frame/sparse.js +432 -0
  388. package/dist/tools/frame/sparse.js.map +1 -0
  389. package/dist/tools/frame/spectral-stack.d.ts +159 -0
  390. package/dist/tools/frame/spectral-stack.js +391 -0
  391. package/dist/tools/frame/spectral-stack.js.map +1 -0
  392. package/dist/tools/frame/spectral.d.ts +222 -0
  393. package/dist/tools/frame/spectral.js +572 -0
  394. package/dist/tools/frame/spectral.js.map +1 -0
  395. package/dist/tools/frame/stack.d.ts +115 -0
  396. package/dist/tools/frame/stack.js +290 -0
  397. package/dist/tools/frame/stack.js.map +1 -0
  398. package/dist/tools/frame/view.d.ts +131 -0
  399. package/dist/tools/frame/view.js +337 -0
  400. package/dist/tools/frame/view.js.map +1 -0
  401. package/dist/tools/index.d.ts +157 -0
  402. package/dist/tools/index.js +132 -0
  403. package/dist/tools/index.js.map +1 -0
  404. package/dist/tools/internal.d.ts +87 -0
  405. package/dist/tools/internal.js +85 -0
  406. package/dist/tools/internal.js.map +1 -0
  407. package/dist/tools/nanovdb/build-from-vdb.d.ts +59 -0
  408. package/dist/tools/nanovdb/build-from-vdb.js +100 -0
  409. package/dist/tools/nanovdb/build-from-vdb.js.map +1 -0
  410. package/dist/tools/nanovdb/bytes.d.ts +233 -0
  411. package/dist/tools/nanovdb/bytes.js +388 -0
  412. package/dist/tools/nanovdb/bytes.js.map +1 -0
  413. package/dist/tools/nanovdb/coarse-first.d.ts +78 -0
  414. package/dist/tools/nanovdb/coarse-first.js +92 -0
  415. package/dist/tools/nanovdb/coarse-first.js.map +1 -0
  416. package/dist/tools/nanovdb/half.d.ts +22 -0
  417. package/dist/tools/nanovdb/half.js +73 -0
  418. package/dist/tools/nanovdb/half.js.map +1 -0
  419. package/dist/tools/nanovdb/index.d.ts +34 -0
  420. package/dist/tools/nanovdb/index.js +25 -0
  421. package/dist/tools/nanovdb/index.js.map +1 -0
  422. package/dist/tools/nanovdb/inspect.d.ts +33 -0
  423. package/dist/tools/nanovdb/inspect.js +70 -0
  424. package/dist/tools/nanovdb/inspect.js.map +1 -0
  425. package/dist/tools/nanovdb/leaf-codec.d.ts +119 -0
  426. package/dist/tools/nanovdb/leaf-codec.js +356 -0
  427. package/dist/tools/nanovdb/leaf-codec.js.map +1 -0
  428. package/dist/tools/nanovdb/quantize.d.ts +72 -0
  429. package/dist/tools/nanovdb/quantize.js +329 -0
  430. package/dist/tools/nanovdb/quantize.js.map +1 -0
  431. package/dist/tools/nanovdb/resample.d.ts +177 -0
  432. package/dist/tools/nanovdb/resample.js +692 -0
  433. package/dist/tools/nanovdb/resample.js.map +1 -0
  434. package/dist/tools/nanovdb/serialize.d.ts +176 -0
  435. package/dist/tools/nanovdb/serialize.js +439 -0
  436. package/dist/tools/nanovdb/serialize.js.map +1 -0
  437. package/dist/tools/nanovdb/stats.d.ts +87 -0
  438. package/dist/tools/nanovdb/stats.js +225 -0
  439. package/dist/tools/nanovdb/stats.js.map +1 -0
  440. package/dist/tools/nanovdb/transform.d.ts +30 -0
  441. package/dist/tools/nanovdb/transform.js +94 -0
  442. package/dist/tools/nanovdb/transform.js.map +1 -0
  443. package/dist/tools/nanovdb/tree.d.ts +186 -0
  444. package/dist/tools/nanovdb/tree.js +530 -0
  445. package/dist/tools/nanovdb/tree.js.map +1 -0
  446. package/dist/tools/nanovdb/write-nvdb.d.ts +74 -0
  447. package/dist/tools/nanovdb/write-nvdb.js +290 -0
  448. package/dist/tools/nanovdb/write-nvdb.js.map +1 -0
  449. package/dist/tools/nvdb-file.d.ts +265 -0
  450. package/dist/tools/nvdb-file.js +763 -0
  451. package/dist/tools/nvdb-file.js.map +1 -0
  452. package/dist/tools/nvdb-stream.d.ts +154 -0
  453. package/dist/tools/nvdb-stream.js +409 -0
  454. package/dist/tools/nvdb-stream.js.map +1 -0
  455. package/dist/tools/reference/analytic.d.ts +41 -0
  456. package/dist/tools/reference/analytic.js +95 -0
  457. package/dist/tools/reference/analytic.js.map +1 -0
  458. package/dist/tools/reference/environment.d.ts +62 -0
  459. package/dist/tools/reference/environment.js +154 -0
  460. package/dist/tools/reference/environment.js.map +1 -0
  461. package/dist/tools/reference/index.d.ts +12 -0
  462. package/dist/tools/reference/index.js +13 -0
  463. package/dist/tools/reference/index.js.map +1 -0
  464. package/dist/tools/reference/media.d.ts +14 -0
  465. package/dist/tools/reference/media.js +30 -0
  466. package/dist/tools/reference/media.js.map +1 -0
  467. package/dist/tools/reference/rng.d.ts +20 -0
  468. package/dist/tools/reference/rng.js +30 -0
  469. package/dist/tools/reference/rng.js.map +1 -0
  470. package/dist/tools/reference/scene.d.ts +312 -0
  471. package/dist/tools/reference/scene.js +169 -0
  472. package/dist/tools/reference/scene.js.map +1 -0
  473. package/dist/tools/reference/tables.d.ts +98 -0
  474. package/dist/tools/reference/tables.js +264 -0
  475. package/dist/tools/reference/tables.js.map +1 -0
  476. package/dist/tools/reference/trace.d.ts +160 -0
  477. package/dist/tools/reference/trace.js +497 -0
  478. package/dist/tools/reference/trace.js.map +1 -0
  479. package/dist/tools/vdb/bit-utils.d.ts +20 -0
  480. package/dist/tools/vdb/bit-utils.js +42 -0
  481. package/dist/tools/vdb/bit-utils.js.map +1 -0
  482. package/dist/tools/vdb/blosc-write.d.ts +43 -0
  483. package/dist/tools/vdb/blosc-write.js +197 -0
  484. package/dist/tools/vdb/blosc-write.js.map +1 -0
  485. package/dist/tools/vdb/blosc.d.ts +86 -0
  486. package/dist/tools/vdb/blosc.js +287 -0
  487. package/dist/tools/vdb/blosc.js.map +1 -0
  488. package/dist/tools/vdb/blosclz.d.ts +33 -0
  489. package/dist/tools/vdb/blosclz.js +112 -0
  490. package/dist/tools/vdb/blosclz.js.map +1 -0
  491. package/dist/tools/vdb/byte-reader.d.ts +50 -0
  492. package/dist/tools/vdb/byte-reader.js +161 -0
  493. package/dist/tools/vdb/byte-reader.js.map +1 -0
  494. package/dist/tools/vdb/compression.d.ts +81 -0
  495. package/dist/tools/vdb/compression.js +260 -0
  496. package/dist/tools/vdb/compression.js.map +1 -0
  497. package/dist/tools/vdb/errors.d.ts +10 -0
  498. package/dist/tools/vdb/errors.js +11 -0
  499. package/dist/tools/vdb/errors.js.map +1 -0
  500. package/dist/tools/vdb/grid.d.ts +37 -0
  501. package/dist/tools/vdb/grid.js +153 -0
  502. package/dist/tools/vdb/grid.js.map +1 -0
  503. package/dist/tools/vdb/half-float.d.ts +9 -0
  504. package/dist/tools/vdb/half-float.js +24 -0
  505. package/dist/tools/vdb/half-float.js.map +1 -0
  506. package/dist/tools/vdb/index.d.ts +4 -0
  507. package/dist/tools/vdb/index.js +3 -0
  508. package/dist/tools/vdb/index.js.map +1 -0
  509. package/dist/tools/vdb/inflate.d.ts +24 -0
  510. package/dist/tools/vdb/inflate.js +334 -0
  511. package/dist/tools/vdb/inflate.js.map +1 -0
  512. package/dist/tools/vdb/lz4.d.ts +30 -0
  513. package/dist/tools/vdb/lz4.js +228 -0
  514. package/dist/tools/vdb/lz4.js.map +1 -0
  515. package/dist/tools/vdb/metadata.d.ts +17 -0
  516. package/dist/tools/vdb/metadata.js +72 -0
  517. package/dist/tools/vdb/metadata.js.map +1 -0
  518. package/dist/tools/vdb/parse.d.ts +47 -0
  519. package/dist/tools/vdb/parse.js +241 -0
  520. package/dist/tools/vdb/parse.js.map +1 -0
  521. package/dist/tools/vdb/point-render-data.d.ts +79 -0
  522. package/dist/tools/vdb/point-render-data.js +137 -0
  523. package/dist/tools/vdb/point-render-data.js.map +1 -0
  524. package/dist/tools/vdb/points.d.ts +186 -0
  525. package/dist/tools/vdb/points.js +835 -0
  526. package/dist/tools/vdb/points.js.map +1 -0
  527. package/dist/tools/vdb/transform.d.ts +23 -0
  528. package/dist/tools/vdb/transform.js +54 -0
  529. package/dist/tools/vdb/transform.js.map +1 -0
  530. package/dist/tools/vdb/tree.d.ts +111 -0
  531. package/dist/tools/vdb/tree.js +228 -0
  532. package/dist/tools/vdb/tree.js.map +1 -0
  533. package/dist/tools/vdb/types.d.ts +195 -0
  534. package/dist/tools/vdb/types.js +3 -0
  535. package/dist/tools/vdb/types.js.map +1 -0
  536. package/dist/tools/wvdb/bake.d.ts +145 -0
  537. package/dist/tools/wvdb/bake.js +361 -0
  538. package/dist/tools/wvdb/bake.js.map +1 -0
  539. package/dist/tools/wvdb/dense.d.ts +191 -0
  540. package/dist/tools/wvdb/dense.js +368 -0
  541. package/dist/tools/wvdb/dense.js.map +1 -0
  542. package/dist/tools/wvdb/format.d.ts +220 -0
  543. package/dist/tools/wvdb/format.js +306 -0
  544. package/dist/tools/wvdb/format.js.map +1 -0
  545. package/dist/tools/wvdb/index.d.ts +14 -0
  546. package/dist/tools/wvdb/index.js +15 -0
  547. package/dist/tools/wvdb/index.js.map +1 -0
  548. package/dist/tools/wvdb/level-set.d.ts +56 -0
  549. package/dist/tools/wvdb/level-set.js +153 -0
  550. package/dist/tools/wvdb/level-set.js.map +1 -0
  551. package/dist/tools/wvdb/nanovdb.d.ts +59 -0
  552. package/dist/tools/wvdb/nanovdb.js +64 -0
  553. package/dist/tools/wvdb/nanovdb.js.map +1 -0
  554. package/dist/tools/wvdb/partial.d.ts +74 -0
  555. package/dist/tools/wvdb/partial.js +233 -0
  556. package/dist/tools/wvdb/partial.js.map +1 -0
  557. package/dist/tools/wvdb/read.d.ts +336 -0
  558. package/dist/tools/wvdb/read.js +766 -0
  559. package/dist/tools/wvdb/read.js.map +1 -0
  560. package/dist/tools/wvdb/sha256.d.ts +7 -0
  561. package/dist/tools/wvdb/sha256.js +76 -0
  562. package/dist/tools/wvdb/sha256.js.map +1 -0
  563. package/dist/tools/wvdb/write.d.ts +149 -0
  564. package/dist/tools/wvdb/write.js +403 -0
  565. package/dist/tools/wvdb/write.js.map +1 -0
  566. package/package.json +83 -4
  567. package/vendor/LICENSE +201 -0
  568. package/vendor/NOTICE +19 -0
  569. package/vendor/VENDOR.md +100 -0
  570. package/vendor/pnanovdb.wgsl +1577 -0
@@ -0,0 +1,161 @@
1
+ /**
2
+ * byte-reader.ts — a seekable little-endian cursor over a `.vdb` buffer.
3
+ *
4
+ * All primitive VDB stream fields (per the `OpenVDBReader`/`vdb-rs` format
5
+ * facts, docs/archive/handoffs and docs/archive/v1/DECISIONS.md D3) are little-endian; strings are a
6
+ * u32 length prefix + raw bytes (no terminator). OpenVDB writes `std::string` bytes as they are, so
7
+ * names and string metadata are UTF-8 in practice; {@link ByteReader.string} decodes UTF-8 and
8
+ * falls back to latin1 for bytes that are not valid UTF-8 (K7.17, his VDB-173).
9
+ */
10
+ import { VdbFormatError } from "./errors.js";
11
+ /**
12
+ * One char per byte, in chunks: about 12x faster than a per-byte `+=` loop
13
+ * (64 MiB: ~0.3 s against ~3.3 s, Node 22, M-series Mac), which matters for
14
+ * a hostile string length.
15
+ */
16
+ function latin1(raw) {
17
+ const CHUNK = 8192;
18
+ let s = "";
19
+ for (let i = 0; i < raw.length; i += CHUNK) {
20
+ s += String.fromCharCode.apply(null, raw.subarray(i, i + CHUNK));
21
+ }
22
+ return s;
23
+ }
24
+ /** Fatal: invalid UTF-8 throws (then {@link decodeVdbString} takes latin1). `ignoreBOM` keeps a
25
+ * leading U+FEFF in the string, as the bytes say. */
26
+ const UTF8 = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
27
+ /**
28
+ * UTF-8 when the bytes are valid UTF-8, else latin1 (one char per byte, never fails). ASCII
29
+ * decodes the same either way. A hostile length costs one native decode pass that stops at
30
+ * the first invalid byte, plus the chunked latin1 pass: linear, no per-byte JS loop (K7.17).
31
+ */
32
+ export function decodeVdbString(raw) {
33
+ try {
34
+ return UTF8.decode(raw);
35
+ }
36
+ catch {
37
+ return latin1(raw);
38
+ }
39
+ }
40
+ export class ByteReader {
41
+ view;
42
+ bytes;
43
+ pos = 0;
44
+ constructor(buffer) {
45
+ this.bytes = new Uint8Array(buffer);
46
+ this.view = new DataView(buffer);
47
+ }
48
+ get length() {
49
+ return this.bytes.length;
50
+ }
51
+ need(count) {
52
+ if (this.pos + count > this.bytes.length) {
53
+ throw new VdbFormatError(`unexpected end of buffer (wanted ${count} bytes at offset ${this.pos}, have ${this.bytes.length})`);
54
+ }
55
+ }
56
+ seek(pos) {
57
+ if (pos < 0 || pos > this.bytes.length) {
58
+ throw new VdbFormatError(`seek out of range: ${pos} (buffer length ${this.bytes.length})`);
59
+ }
60
+ this.pos = pos;
61
+ }
62
+ skip(count) {
63
+ this.seek(this.pos + count);
64
+ }
65
+ u8() {
66
+ this.need(1);
67
+ return this.bytes[this.pos++];
68
+ }
69
+ bool() {
70
+ return this.u8() !== 0;
71
+ }
72
+ u16() {
73
+ this.need(2);
74
+ const v = this.view.getUint16(this.pos, true);
75
+ this.pos += 2;
76
+ return v;
77
+ }
78
+ i32() {
79
+ this.need(4);
80
+ const v = this.view.getInt32(this.pos, true);
81
+ this.pos += 4;
82
+ return v;
83
+ }
84
+ u32() {
85
+ this.need(4);
86
+ const v = this.view.getUint32(this.pos, true);
87
+ this.pos += 4;
88
+ return v;
89
+ }
90
+ u64() {
91
+ this.need(8);
92
+ const v = this.view.getBigUint64(this.pos, true);
93
+ this.pos += 8;
94
+ return v;
95
+ }
96
+ /** u64 narrowed to `number` — safe for stream offsets/counts on real files
97
+ * (well under 2^53), throws rather than silently truncating otherwise. */
98
+ u64AsNumber() {
99
+ const v = this.u64();
100
+ if (v > BigInt(Number.MAX_SAFE_INTEGER)) {
101
+ throw new VdbFormatError(`u64 value ${v} exceeds safe integer range`);
102
+ }
103
+ return Number(v);
104
+ }
105
+ f32() {
106
+ this.need(4);
107
+ const v = this.view.getFloat32(this.pos, true);
108
+ this.pos += 4;
109
+ return v;
110
+ }
111
+ f64() {
112
+ this.need(8);
113
+ const v = this.view.getFloat64(this.pos, true);
114
+ this.pos += 8;
115
+ return v;
116
+ }
117
+ f16AsF32(halfToFloat) {
118
+ this.need(2);
119
+ const h = this.view.getUint16(this.pos, true);
120
+ this.pos += 2;
121
+ return halfToFloat(h);
122
+ }
123
+ bytes_(count) {
124
+ this.need(count);
125
+ const out = this.bytes.subarray(this.pos, this.pos + count);
126
+ this.pos += count;
127
+ return out;
128
+ }
129
+ /** u32 length prefix + that many bytes (VDB's `readString`), as UTF-8 with a latin1 fallback. */
130
+ string() {
131
+ const len = this.u32();
132
+ return decodeVdbString(this.bytes_(len));
133
+ }
134
+ /** Fixed-length string (no length prefix): `string` metadata values, as UTF-8 with a latin1 fallback. */
135
+ textOf(len) {
136
+ return decodeVdbString(this.bytes_(len));
137
+ }
138
+ /** Fixed-length ASCII string (no length prefix), one char per byte: the UUID. */
139
+ fixedString(len) {
140
+ return latin1(this.bytes_(len));
141
+ }
142
+ vec3i() {
143
+ return [this.i32(), this.i32(), this.i32()];
144
+ }
145
+ vec3d() {
146
+ return [this.f64(), this.f64(), this.f64()];
147
+ }
148
+ /** Reads `bitCount` mask bits as `bitCount/32` little-endian u32 words.
149
+ * (On disk these are u64 LE words; splitting each into two u32 LE words
150
+ * preserves bit-for-bit ordinal position — see bit-utils.ts.) */
151
+ maskWords(bitCount) {
152
+ if (bitCount % 32 !== 0) {
153
+ throw new VdbFormatError(`mask bit count ${bitCount} is not a multiple of 32`);
154
+ }
155
+ const words = new Uint32Array(bitCount / 32);
156
+ for (let i = 0; i < words.length; i++)
157
+ words[i] = this.u32();
158
+ return words;
159
+ }
160
+ }
161
+ //# sourceMappingURL=byte-reader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"byte-reader.js","sourceRoot":"","sources":["../../../src/tools/vdb/byte-reader.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C;;;;GAIG;AACH,SAAS,MAAM,CAAC,GAAe;IAC7B,MAAM,KAAK,GAAG,IAAI,CAAC;IACnB,IAAI,CAAC,GAAG,EAAE,CAAC;IACX,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC;QAC3C,CAAC,IAAI,MAAM,CAAC,YAAY,CAA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CAAC,MAAM,EAAE,CAAC,EAAE;YAAE,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC7D,OAAO,KAAK,CAAC;IACf,CAAC;CACF","sourcesContent":["/**\n * byte-reader.ts — a seekable little-endian cursor over a `.vdb` buffer.\n *\n * All primitive VDB stream fields (per the `OpenVDBReader`/`vdb-rs` format\n * facts, docs/archive/handoffs and docs/archive/v1/DECISIONS.md D3) are little-endian; strings are a\n * u32 length prefix + raw bytes (no terminator). OpenVDB writes `std::string` bytes as they are, so\n * names and string metadata are UTF-8 in practice; {@link ByteReader.string} decodes UTF-8 and\n * falls back to latin1 for bytes that are not valid UTF-8 (K7.17, his VDB-173).\n */\n\nimport { VdbFormatError } from \"./errors.js\";\n\n/**\n * One char per byte, in chunks: about 12x faster than a per-byte `+=` loop\n * (64 MiB: ~0.3 s against ~3.3 s, Node 22, M-series Mac), which matters for\n * a hostile string length.\n */\nfunction latin1(raw: Uint8Array): string {\n const CHUNK = 8192;\n let s = \"\";\n for (let i = 0; i < raw.length; i += CHUNK) {\n s += String.fromCharCode.apply(null, raw.subarray(i, i + CHUNK) as unknown as number[]);\n }\n return s;\n}\n\n/** Fatal: invalid UTF-8 throws (then {@link decodeVdbString} takes latin1). `ignoreBOM` keeps a\n * leading U+FEFF in the string, as the bytes say. */\nconst UTF8 = new TextDecoder(\"utf-8\", { fatal: true, ignoreBOM: true });\n\n/**\n * UTF-8 when the bytes are valid UTF-8, else latin1 (one char per byte, never fails). ASCII\n * decodes the same either way. A hostile length costs one native decode pass that stops at\n * the first invalid byte, plus the chunked latin1 pass: linear, no per-byte JS loop (K7.17).\n */\nexport function decodeVdbString(raw: Uint8Array): string {\n try {\n return UTF8.decode(raw);\n } catch {\n return latin1(raw);\n }\n}\n\nexport class ByteReader {\n private readonly view: DataView;\n private readonly bytes: Uint8Array;\n pos = 0;\n\n constructor(buffer: ArrayBuffer) {\n this.bytes = new Uint8Array(buffer);\n this.view = new DataView(buffer);\n }\n\n get length(): number {\n return this.bytes.length;\n }\n\n private need(count: number): void {\n if (this.pos + count > this.bytes.length) {\n throw new VdbFormatError(\n `unexpected end of buffer (wanted ${count} bytes at offset ${this.pos}, have ${this.bytes.length})`,\n );\n }\n }\n\n seek(pos: number): void {\n if (pos < 0 || pos > this.bytes.length) {\n throw new VdbFormatError(`seek out of range: ${pos} (buffer length ${this.bytes.length})`);\n }\n this.pos = pos;\n }\n\n skip(count: number): void {\n this.seek(this.pos + count);\n }\n\n u8(): number {\n this.need(1);\n return this.bytes[this.pos++]!;\n }\n\n bool(): boolean {\n return this.u8() !== 0;\n }\n\n u16(): number {\n this.need(2);\n const v = this.view.getUint16(this.pos, true);\n this.pos += 2;\n return v;\n }\n\n i32(): number {\n this.need(4);\n const v = this.view.getInt32(this.pos, true);\n this.pos += 4;\n return v;\n }\n\n u32(): number {\n this.need(4);\n const v = this.view.getUint32(this.pos, true);\n this.pos += 4;\n return v;\n }\n\n u64(): bigint {\n this.need(8);\n const v = this.view.getBigUint64(this.pos, true);\n this.pos += 8;\n return v;\n }\n\n /** u64 narrowed to `number` — safe for stream offsets/counts on real files\n * (well under 2^53), throws rather than silently truncating otherwise. */\n u64AsNumber(): number {\n const v = this.u64();\n if (v > BigInt(Number.MAX_SAFE_INTEGER)) {\n throw new VdbFormatError(`u64 value ${v} exceeds safe integer range`);\n }\n return Number(v);\n }\n\n f32(): number {\n this.need(4);\n const v = this.view.getFloat32(this.pos, true);\n this.pos += 4;\n return v;\n }\n\n f64(): number {\n this.need(8);\n const v = this.view.getFloat64(this.pos, true);\n this.pos += 8;\n return v;\n }\n\n f16AsF32(halfToFloat: (h: number) => number): number {\n this.need(2);\n const h = this.view.getUint16(this.pos, true);\n this.pos += 2;\n return halfToFloat(h);\n }\n\n bytes_(count: number): Uint8Array {\n this.need(count);\n const out = this.bytes.subarray(this.pos, this.pos + count);\n this.pos += count;\n return out;\n }\n\n /** u32 length prefix + that many bytes (VDB's `readString`), as UTF-8 with a latin1 fallback. */\n string(): string {\n const len = this.u32();\n return decodeVdbString(this.bytes_(len));\n }\n\n /** Fixed-length string (no length prefix): `string` metadata values, as UTF-8 with a latin1 fallback. */\n textOf(len: number): string {\n return decodeVdbString(this.bytes_(len));\n }\n\n /** Fixed-length ASCII string (no length prefix), one char per byte: the UUID. */\n fixedString(len: number): string {\n return latin1(this.bytes_(len));\n }\n\n vec3i(): [number, number, number] {\n return [this.i32(), this.i32(), this.i32()];\n }\n\n vec3d(): [number, number, number] {\n return [this.f64(), this.f64(), this.f64()];\n }\n\n /** Reads `bitCount` mask bits as `bitCount/32` little-endian u32 words.\n * (On disk these are u64 LE words; splitting each into two u32 LE words\n * preserves bit-for-bit ordinal position — see bit-utils.ts.) */\n maskWords(bitCount: number): Uint32Array {\n if (bitCount % 32 !== 0) {\n throw new VdbFormatError(`mask bit count ${bitCount} is not a multiple of 32`);\n }\n const words = new Uint32Array(bitCount / 32);\n for (let i = 0; i < words.length; i++) words[i] = this.u32();\n return words;\n }\n}\n"]}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * compression.ts — per-node value array (de)serialization.
3
+ *
4
+ * This is the risky, easy-to-get-subtly-wrong part of the format: OpenVDB's
5
+ * "node mask compression" scheme (file version >= 222) can omit inactive
6
+ * values entirely, storing only the active ones plus up to two "inactive
7
+ * fill" values and a second selection mask to tell them apart — then the
8
+ * reader has to re-expand that sparse array back to the node's full
9
+ * `dim^3` table. Algorithm and field order lifted (format facts only, not
10
+ * code) from `vdb-rs`'s `read_compressed`/`read_compressed_data`, which is
11
+ * the more careful of the two references (the `mjurczyk/openvdb` JS reader
12
+ * never actually implements leaf value decoding at all — see grid.ts docs),
13
+ * and checked against OpenVDB `io/Compression.h` (`readCompressedValues`,
14
+ * `HalfReader`, `readData`).
15
+ *
16
+ * K4.2: values are no longer float-only. A {@link ValueFormat} describes the
17
+ * grid's `ValueType` (float, vec3s, vec3d, vec3i, PointDataIndex32); decoded
18
+ * values land in a `Float32Array` with `components` scalars per value.
19
+ */
20
+ import type { ByteReader } from "./byte-reader.js";
21
+ export interface CompressionFlags {
22
+ zip: boolean;
23
+ activeMask: boolean;
24
+ blosc: boolean;
25
+ }
26
+ export declare function compressionFromBits(bits: number): CompressionFlags;
27
+ /**
28
+ * On-disk encoding of one value component at full precision. `f16` is a
29
+ * `HalfGrid` (`math::half`, OpenVDB 13+), whose full width *is* 16 bits.
30
+ */
31
+ export type ComponentKind = "f16" | "f32" | "f64" | "i32" | "u32";
32
+ /**
33
+ * How a grid's `ValueType` is laid out on disk: `components` scalars of
34
+ * `kind` each (`sizeof(ValueType) = components * bytes(kind)`). Decoded values
35
+ * always land in a `Float32Array`, `components` entries per value (xyz
36
+ * interleaved for vectors). That is exact for f16 and f32, and for i32/u32
37
+ * below 2^24; f64 is narrowed to f32.
38
+ */
39
+ export interface ValueFormat {
40
+ readonly components: 1 | 3;
41
+ readonly kind: ComponentKind;
42
+ }
43
+ export declare const FLOAT_FORMAT: ValueFormat;
44
+ export declare const VEC3S_FORMAT: ValueFormat;
45
+ export declare const VEC3D_FORMAT: ValueFormat;
46
+ export declare const VEC3I_FORMAT: ValueFormat;
47
+ /** `PointDataIndex32`: internal-node and root values of a point data grid. */
48
+ export declare const PTDATAIDX32_FORMAT: ValueFormat;
49
+ /** `math::half` (`Tree_half_5_4_3`, K7.C): every value, background and tile is 2 bytes. */
50
+ export declare const HALF_FORMAT: ValueFormat;
51
+ /** `sizeof(ValueType)` at full precision. */
52
+ export declare function valueBytes(format: ValueFormat): number;
53
+ /**
54
+ * OpenVDB `RealToHalf<T>::isReal`: half-float storage applies to float,
55
+ * double and their vector types only. An integer grid "saved as half" still
56
+ * writes full-width values (`HalfReader<false, T>` is plain `readData`), and
57
+ * so does a `HalfGrid` (`RealToHalf<half>` is the generic `isReal = false`):
58
+ * its values are already halves, read through plain `readData`, so the
59
+ * empty-array rule of `HalfReader<true, T>` (K4.7) does not apply to it.
60
+ */
61
+ export declare function isRealFormat(format: ValueFormat): boolean;
62
+ /** Reads one full-width `ValueType` (root background, root tiles, inactive fill values). */
63
+ export declare function readFullValue(reader: ByteReader, format: ValueFormat): number[];
64
+ export interface ReadCompressedOptions {
65
+ fileVersion: number;
66
+ compression: CompressionFlags;
67
+ /** The grid was saved as half float (honoured for real formats only). */
68
+ useHalf: boolean;
69
+ /** The grid background, `format.components` entries. */
70
+ background: ArrayLike<number>;
71
+ /** Full logical size of this node's value table (32768 / 4096 / 512). */
72
+ numValues: number;
73
+ valueMask: Uint32Array;
74
+ /** Value layout. Default: {@link FLOAT_FORMAT}. */
75
+ format?: ValueFormat;
76
+ }
77
+ /** The generic "node value array" reader — used for internal-node tile
78
+ * values (Node5/Node4) and leaf voxel values alike; both go through the
79
+ * same on-disk encoding (`io::Compression::readCompressedValues`). Returns
80
+ * `numValues * format.components` scalars. */
81
+ export declare function readCompressedValues(reader: ByteReader, opts: ReadCompressedOptions): Float32Array;
@@ -0,0 +1,260 @@
1
+ /**
2
+ * compression.ts — per-node value array (de)serialization.
3
+ *
4
+ * This is the risky, easy-to-get-subtly-wrong part of the format: OpenVDB's
5
+ * "node mask compression" scheme (file version >= 222) can omit inactive
6
+ * values entirely, storing only the active ones plus up to two "inactive
7
+ * fill" values and a second selection mask to tell them apart — then the
8
+ * reader has to re-expand that sparse array back to the node's full
9
+ * `dim^3` table. Algorithm and field order lifted (format facts only, not
10
+ * code) from `vdb-rs`'s `read_compressed`/`read_compressed_data`, which is
11
+ * the more careful of the two references (the `mjurczyk/openvdb` JS reader
12
+ * never actually implements leaf value decoding at all — see grid.ts docs),
13
+ * and checked against OpenVDB `io/Compression.h` (`readCompressedValues`,
14
+ * `HalfReader`, `readData`).
15
+ *
16
+ * K4.2: values are no longer float-only. A {@link ValueFormat} describes the
17
+ * grid's `ValueType` (float, vec3s, vec3d, vec3i, PointDataIndex32); decoded
18
+ * values land in a `Float32Array` with `components` scalars per value.
19
+ */
20
+ import { countBits, testBit } from "./bit-utils.js";
21
+ import { decompressBlosc } from "./blosc.js";
22
+ import { VdbFormatError } from "./errors.js";
23
+ import { halfToFloat } from "./half-float.js";
24
+ import { inflateZlib } from "./inflate.js";
25
+ export function compressionFromBits(bits) {
26
+ return {
27
+ zip: (bits & 0x1) !== 0,
28
+ activeMask: (bits & 0x2) !== 0,
29
+ blosc: (bits & 0x4) !== 0,
30
+ };
31
+ }
32
+ /** `NodeMetaData` (openvdb/io/Compression.h) — how a node's value array was
33
+ * reduced before writing, when node-mask compression (v222+) is in play. */
34
+ var NodeMetaData;
35
+ (function (NodeMetaData) {
36
+ NodeMetaData[NodeMetaData["NoMaskOrInactiveVals"] = 0] = "NoMaskOrInactiveVals";
37
+ NodeMetaData[NodeMetaData["NoMaskAndMinusBg"] = 1] = "NoMaskAndMinusBg";
38
+ NodeMetaData[NodeMetaData["NoMaskAndOneInactiveVal"] = 2] = "NoMaskAndOneInactiveVal";
39
+ NodeMetaData[NodeMetaData["MaskAndNoInactiveVals"] = 3] = "MaskAndNoInactiveVals";
40
+ NodeMetaData[NodeMetaData["MaskAndOneInactiveVal"] = 4] = "MaskAndOneInactiveVal";
41
+ NodeMetaData[NodeMetaData["MaskAndTwoInactiveVals"] = 5] = "MaskAndTwoInactiveVals";
42
+ NodeMetaData[NodeMetaData["NoMaskAndAllVals"] = 6] = "NoMaskAndAllVals";
43
+ })(NodeMetaData || (NodeMetaData = {}));
44
+ export const FLOAT_FORMAT = { components: 1, kind: "f32" };
45
+ export const VEC3S_FORMAT = { components: 3, kind: "f32" };
46
+ export const VEC3D_FORMAT = { components: 3, kind: "f64" };
47
+ export const VEC3I_FORMAT = { components: 3, kind: "i32" };
48
+ /** `PointDataIndex32`: internal-node and root values of a point data grid. */
49
+ export const PTDATAIDX32_FORMAT = { components: 1, kind: "u32" };
50
+ /** `math::half` (`Tree_half_5_4_3`, K7.C): every value, background and tile is 2 bytes. */
51
+ export const HALF_FORMAT = { components: 1, kind: "f16" };
52
+ const KIND_BYTES = { f16: 2, f32: 4, f64: 8, i32: 4, u32: 4 };
53
+ /** `sizeof(ValueType)` at full precision. */
54
+ export function valueBytes(format) {
55
+ return format.components * KIND_BYTES[format.kind];
56
+ }
57
+ /**
58
+ * OpenVDB `RealToHalf<T>::isReal`: half-float storage applies to float,
59
+ * double and their vector types only. An integer grid "saved as half" still
60
+ * writes full-width values (`HalfReader<false, T>` is plain `readData`), and
61
+ * so does a `HalfGrid` (`RealToHalf<half>` is the generic `isReal = false`):
62
+ * its values are already halves, read through plain `readData`, so the
63
+ * empty-array rule of `HalfReader<true, T>` (K4.7) does not apply to it.
64
+ */
65
+ export function isRealFormat(format) {
66
+ return format.kind === "f32" || format.kind === "f64";
67
+ }
68
+ function readComponent(reader, kind) {
69
+ switch (kind) {
70
+ case "f16":
71
+ return halfToFloat(reader.u16());
72
+ case "f32":
73
+ return reader.f32();
74
+ case "f64":
75
+ return reader.f64();
76
+ case "i32":
77
+ return reader.i32();
78
+ case "u32":
79
+ return reader.u32();
80
+ }
81
+ }
82
+ /** Reads one full-width `ValueType` (root background, root tiles, inactive fill values). */
83
+ export function readFullValue(reader, format) {
84
+ const out = new Array(format.components);
85
+ for (let c = 0; c < format.components; c++)
86
+ out[c] = readComponent(reader, format.kind);
87
+ return out;
88
+ }
89
+ /** Decodes `scalars` little-endian scalars of `kind` (or halves) into a new `Float32Array`. */
90
+ function decodeScalars(raw, scalars, kind, half) {
91
+ const view = new DataView(raw.buffer, raw.byteOffset, raw.byteLength);
92
+ const out = new Float32Array(scalars);
93
+ if (half) {
94
+ for (let i = 0; i < scalars; i++)
95
+ out[i] = halfToFloat(view.getUint16(i * 2, true));
96
+ return out;
97
+ }
98
+ switch (kind) {
99
+ case "f16":
100
+ for (let i = 0; i < scalars; i++)
101
+ out[i] = halfToFloat(view.getUint16(i * 2, true));
102
+ break;
103
+ case "f32":
104
+ for (let i = 0; i < scalars; i++)
105
+ out[i] = view.getFloat32(i * 4, true);
106
+ break;
107
+ case "f64":
108
+ for (let i = 0; i < scalars; i++)
109
+ out[i] = view.getFloat64(i * 8, true);
110
+ break;
111
+ case "i32":
112
+ for (let i = 0; i < scalars; i++)
113
+ out[i] = view.getInt32(i * 4, true);
114
+ break;
115
+ case "u32":
116
+ for (let i = 0; i < scalars; i++)
117
+ out[i] = view.getUint32(i * 4, true);
118
+ break;
119
+ }
120
+ return out;
121
+ }
122
+ /** Reads the raw (pre node-mask-expansion) value payload: `count` values
123
+ * (`count * components` scalars), each full width or half, through
124
+ * blosc/zip/no compression (`io::readData` / `io::HalfReader::read`). */
125
+ function readRawValues(reader, count, half, format, compression) {
126
+ const scalarBytes = half ? 2 : KIND_BYTES[format.kind];
127
+ const elementSize = scalarBytes * format.components;
128
+ const decodeBytes = (raw, n) => {
129
+ if (raw.length < n * elementSize) {
130
+ throw new VdbFormatError(`value payload is ${raw.length} bytes, expected ${n * elementSize}`);
131
+ }
132
+ return decodeScalars(raw, n * format.components, format.kind, half);
133
+ };
134
+ const readPlain = (n) => decodeBytes(reader.bytes_(n * elementSize), n);
135
+ /** The `<= 0` sentinel: raw values follow, `-n / elementSize` of them. */
136
+ const readSentinelRaw = (numBytes) => {
137
+ const rawCount = -numBytes / elementSize;
138
+ if (!Number.isInteger(rawCount) || rawCount < 0 || rawCount > count) {
139
+ throw new VdbFormatError(`raw-value sentinel ${numBytes} is not a whole number of ${elementSize}-byte values within the expected ${count}`);
140
+ }
141
+ return readPlain(rawCount);
142
+ };
143
+ if (compression.blosc) {
144
+ const numCompressedBytes = readI64AsNumber(reader);
145
+ if (numCompressedBytes <= 0)
146
+ return readSentinelRaw(numCompressedBytes);
147
+ // OpenVDB pads buffers shorter than Blosc's 48-byte minimum before
148
+ // compressing, so the frame can decode to more than `count` values.
149
+ const maxBytes = Math.max(count * elementSize, 48);
150
+ const decoded = decompressBlosc(reader.bytes_(numCompressedBytes), {
151
+ maxBytes,
152
+ expectedCbytes: numCompressedBytes,
153
+ });
154
+ if (decoded.length < count * elementSize) {
155
+ throw new VdbFormatError(`blosc frame decoded to ${decoded.length} bytes, expected ${count * elementSize}`);
156
+ }
157
+ return decodeBytes(decoded.subarray(0, count * elementSize), count);
158
+ }
159
+ if (compression.zip) {
160
+ const numZippedBytes = readI64AsNumber(reader);
161
+ if (numZippedBytes <= 0)
162
+ return readSentinelRaw(numZippedBytes);
163
+ const zippedBytes = reader.bytes_(numZippedBytes);
164
+ const inflated = inflateZlib(zippedBytes, count * elementSize);
165
+ return decodeBytes(inflated.subarray(0, count * elementSize), count);
166
+ }
167
+ return readPlain(count);
168
+ }
169
+ /** Reads a signed 64-bit stream field narrowed to `number` (compressed byte
170
+ * counts are written as `int64_t` and can legitimately be <= 0 as a
171
+ * "not worth compressing, here's the raw size instead" sentinel). */
172
+ function readI64AsNumber(reader) {
173
+ const bytes = reader.bytes_(8);
174
+ const view = new DataView(bytes.buffer, bytes.byteOffset, 8);
175
+ const v = view.getBigInt64(0, true);
176
+ if (v > BigInt(Number.MAX_SAFE_INTEGER) || v < -BigInt(Number.MAX_SAFE_INTEGER)) {
177
+ throw new VdbFormatError(`i64 value ${v} exceeds safe integer range`);
178
+ }
179
+ return Number(v);
180
+ }
181
+ /** The generic "node value array" reader — used for internal-node tile
182
+ * values (Node5/Node4) and leaf voxel values alike; both go through the
183
+ * same on-disk encoding (`io::Compression::readCompressedValues`). Returns
184
+ * `numValues * format.components` scalars. */
185
+ export function readCompressedValues(reader, opts) {
186
+ const { fileVersion, compression, numValues, valueMask } = opts;
187
+ const format = opts.format ?? FLOAT_FORMAT;
188
+ const comps = format.components;
189
+ const half = opts.useHalf && isRealFormat(format);
190
+ let meta = NodeMetaData.NoMaskOrInactiveVals;
191
+ if (fileVersion >= 222) {
192
+ meta = reader.u8();
193
+ }
194
+ // Inactive fill values, exactly as `io::readCompressedValues`:
195
+ // inactiveVal1 = background
196
+ // inactiveVal0 = (meta == NoMaskOrInactiveVals) ? background : -background
197
+ // then one or two values read from the stream override them (written at
198
+ // full `sizeof(ValueType)`, even for half-float grids). K4.8.
199
+ const bg = Array.from({ length: comps }, (_, c) => opts.background[c]);
200
+ const negBg = bg.map((v) => -v);
201
+ let inactiveVal0 = meta === NodeMetaData.NoMaskOrInactiveVals ? bg : negBg;
202
+ let inactiveVal1 = bg;
203
+ if (meta === NodeMetaData.NoMaskAndOneInactiveVal ||
204
+ meta === NodeMetaData.MaskAndOneInactiveVal ||
205
+ meta === NodeMetaData.MaskAndTwoInactiveVals) {
206
+ inactiveVal0 = readFullValue(reader, format);
207
+ if (meta === NodeMetaData.MaskAndTwoInactiveVals)
208
+ inactiveVal1 = readFullValue(reader, format);
209
+ }
210
+ let selectionMask = null;
211
+ if (meta === NodeMetaData.MaskAndNoInactiveVals ||
212
+ meta === NodeMetaData.MaskAndOneInactiveVal ||
213
+ meta === NodeMetaData.MaskAndTwoInactiveVals) {
214
+ selectionMask = reader.maskWords(numValues);
215
+ }
216
+ const onDiskCount = compression.activeMask && meta !== NodeMetaData.NoMaskAndAllVals && fileVersion >= 222
217
+ ? countBits(valueMask)
218
+ : numValues;
219
+ // K4.7: `io::HalfReader<true, T>::read` returns before touching the stream
220
+ // when `count < 1`, because `HalfWriter<true, T>::write` writes nothing for
221
+ // an empty array, not even the blosc/zip size field. So a half-float node
222
+ // whose mask compression leaves no values (an internal node without active
223
+ // tiles, typically) has no payload at all. Full-width and integer arrays go
224
+ // through plain `readData`, which still reads the size field for count 0.
225
+ const raw = half && onDiskCount < 1 ? new Float32Array(0) : readRawValues(reader, onDiskCount, half, format, compression);
226
+ if (raw.length !== onDiskCount * comps) {
227
+ throw new VdbFormatError(`node value payload holds ${raw.length / comps} values, expected ${onDiskCount}`);
228
+ }
229
+ if (compression.activeMask && onDiskCount !== numValues) {
230
+ const expanded = new Float32Array(numValues * comps);
231
+ let readIdx = 0;
232
+ if (comps === 1) {
233
+ const fill0 = inactiveVal0[0];
234
+ const fill1 = inactiveVal1[0];
235
+ for (let i = 0; i < numValues; i++) {
236
+ if (testBit(valueMask, i))
237
+ expanded[i] = raw[readIdx++];
238
+ else
239
+ expanded[i] = selectionMask && testBit(selectionMask, i) ? fill1 : fill0;
240
+ }
241
+ return expanded;
242
+ }
243
+ for (let i = 0; i < numValues; i++) {
244
+ let src = inactiveVal0;
245
+ let srcBase = 0;
246
+ if (testBit(valueMask, i)) {
247
+ src = raw;
248
+ srcBase = readIdx++ * comps;
249
+ }
250
+ else if (selectionMask && testBit(selectionMask, i)) {
251
+ src = inactiveVal1;
252
+ }
253
+ for (let c = 0; c < comps; c++)
254
+ expanded[i * comps + c] = src[srcBase + c];
255
+ }
256
+ return expanded;
257
+ }
258
+ return raw;
259
+ }
260
+ //# sourceMappingURL=compression.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compression.js","sourceRoot":"","sources":["../../../src/tools/vdb/compression.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEpD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAQ3C,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC9C,OAAO;QACL,GAAG,EAAE,CAAC,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC;QACvB,UAAU,EAAE,CAAC,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC;QAC9B,KAAK,EAAE,CAAC,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC;KAC1B,CAAC;AACJ,CAAC;AAED;6EAC6E;AAC7E,IAAW,YAQV;AARD,WAAW,YAAY;IACrB,+EAAwB,CAAA;IACxB,uEAAoB,CAAA;IACpB,qFAA2B,CAAA;IAC3B,iFAAyB,CAAA;IACzB,iFAAyB,CAAA;IACzB,mFAA0B,CAAA;IAC1B,uEAAoB,CAAA;AACtB,CAAC,EARU,YAAY,KAAZ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YAAY,CAAC;YACrB,CAAC;YACD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE;gBAAE,QAAQ,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,OAAO,GAAG,CAAC,CAAE,CAAC;QAC9E,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["/**\n * compression.ts — per-node value array (de)serialization.\n *\n * This is the risky, easy-to-get-subtly-wrong part of the format: OpenVDB's\n * \"node mask compression\" scheme (file version >= 222) can omit inactive\n * values entirely, storing only the active ones plus up to two \"inactive\n * fill\" values and a second selection mask to tell them apart — then the\n * reader has to re-expand that sparse array back to the node's full\n * `dim^3` table. Algorithm and field order lifted (format facts only, not\n * code) from `vdb-rs`'s `read_compressed`/`read_compressed_data`, which is\n * the more careful of the two references (the `mjurczyk/openvdb` JS reader\n * never actually implements leaf value decoding at all — see grid.ts docs),\n * and checked against OpenVDB `io/Compression.h` (`readCompressedValues`,\n * `HalfReader`, `readData`).\n *\n * K4.2: values are no longer float-only. A {@link ValueFormat} describes the\n * grid's `ValueType` (float, vec3s, vec3d, vec3i, PointDataIndex32); decoded\n * values land in a `Float32Array` with `components` scalars per value.\n */\n\nimport { countBits, testBit } from \"./bit-utils.js\";\nimport type { ByteReader } from \"./byte-reader.js\";\nimport { decompressBlosc } from \"./blosc.js\";\nimport { VdbFormatError } from \"./errors.js\";\nimport { halfToFloat } from \"./half-float.js\";\nimport { inflateZlib } from \"./inflate.js\";\n\nexport interface CompressionFlags {\n zip: boolean;\n activeMask: boolean;\n blosc: boolean;\n}\n\nexport function compressionFromBits(bits: number): CompressionFlags {\n return {\n zip: (bits & 0x1) !== 0,\n activeMask: (bits & 0x2) !== 0,\n blosc: (bits & 0x4) !== 0,\n };\n}\n\n/** `NodeMetaData` (openvdb/io/Compression.h) — how a node's value array was\n * reduced before writing, when node-mask compression (v222+) is in play. */\nconst enum NodeMetaData {\n NoMaskOrInactiveVals = 0,\n NoMaskAndMinusBg = 1,\n NoMaskAndOneInactiveVal = 2,\n MaskAndNoInactiveVals = 3,\n MaskAndOneInactiveVal = 4,\n MaskAndTwoInactiveVals = 5,\n NoMaskAndAllVals = 6,\n}\n\n// ---------------------------------------------------------------------------\n// Value formats\n// ---------------------------------------------------------------------------\n\n/**\n * On-disk encoding of one value component at full precision. `f16` is a\n * `HalfGrid` (`math::half`, OpenVDB 13+), whose full width *is* 16 bits.\n */\nexport type ComponentKind = \"f16\" | \"f32\" | \"f64\" | \"i32\" | \"u32\";\n\n/**\n * How a grid's `ValueType` is laid out on disk: `components` scalars of\n * `kind` each (`sizeof(ValueType) = components * bytes(kind)`). Decoded values\n * always land in a `Float32Array`, `components` entries per value (xyz\n * interleaved for vectors). That is exact for f16 and f32, and for i32/u32\n * below 2^24; f64 is narrowed to f32.\n */\nexport interface ValueFormat {\n readonly components: 1 | 3;\n readonly kind: ComponentKind;\n}\n\nexport const FLOAT_FORMAT: ValueFormat = { components: 1, kind: \"f32\" };\nexport const VEC3S_FORMAT: ValueFormat = { components: 3, kind: \"f32\" };\nexport const VEC3D_FORMAT: ValueFormat = { components: 3, kind: \"f64\" };\nexport const VEC3I_FORMAT: ValueFormat = { components: 3, kind: \"i32\" };\n/** `PointDataIndex32`: internal-node and root values of a point data grid. */\nexport const PTDATAIDX32_FORMAT: ValueFormat = { components: 1, kind: \"u32\" };\n/** `math::half` (`Tree_half_5_4_3`, K7.C): every value, background and tile is 2 bytes. */\nexport const HALF_FORMAT: ValueFormat = { components: 1, kind: \"f16\" };\n\nconst KIND_BYTES: Record<ComponentKind, number> = { f16: 2, f32: 4, f64: 8, i32: 4, u32: 4 };\n\n/** `sizeof(ValueType)` at full precision. */\nexport function valueBytes(format: ValueFormat): number {\n return format.components * KIND_BYTES[format.kind];\n}\n\n/**\n * OpenVDB `RealToHalf<T>::isReal`: half-float storage applies to float,\n * double and their vector types only. An integer grid \"saved as half\" still\n * writes full-width values (`HalfReader<false, T>` is plain `readData`), and\n * so does a `HalfGrid` (`RealToHalf<half>` is the generic `isReal = false`):\n * its values are already halves, read through plain `readData`, so the\n * empty-array rule of `HalfReader<true, T>` (K4.7) does not apply to it.\n */\nexport function isRealFormat(format: ValueFormat): boolean {\n return format.kind === \"f32\" || format.kind === \"f64\";\n}\n\nfunction readComponent(reader: ByteReader, kind: ComponentKind): number {\n switch (kind) {\n case \"f16\":\n return halfToFloat(reader.u16());\n case \"f32\":\n return reader.f32();\n case \"f64\":\n return reader.f64();\n case \"i32\":\n return reader.i32();\n case \"u32\":\n return reader.u32();\n }\n}\n\n/** Reads one full-width `ValueType` (root background, root tiles, inactive fill values). */\nexport function readFullValue(reader: ByteReader, format: ValueFormat): number[] {\n const out = new Array<number>(format.components);\n for (let c = 0; c < format.components; c++) out[c] = readComponent(reader, format.kind);\n return out;\n}\n\n/** Decodes `scalars` little-endian scalars of `kind` (or halves) into a new `Float32Array`. */\nfunction decodeScalars(raw: Uint8Array, scalars: number, kind: ComponentKind, half: boolean): Float32Array {\n const view = new DataView(raw.buffer, raw.byteOffset, raw.byteLength);\n const out = new Float32Array(scalars);\n if (half) {\n for (let i = 0; i < scalars; i++) out[i] = halfToFloat(view.getUint16(i * 2, true));\n return out;\n }\n switch (kind) {\n case \"f16\":\n for (let i = 0; i < scalars; i++) out[i] = halfToFloat(view.getUint16(i * 2, true));\n break;\n case \"f32\":\n for (let i = 0; i < scalars; i++) out[i] = view.getFloat32(i * 4, true);\n break;\n case \"f64\":\n for (let i = 0; i < scalars; i++) out[i] = view.getFloat64(i * 8, true);\n break;\n case \"i32\":\n for (let i = 0; i < scalars; i++) out[i] = view.getInt32(i * 4, true);\n break;\n case \"u32\":\n for (let i = 0; i < scalars; i++) out[i] = view.getUint32(i * 4, true);\n break;\n }\n return out;\n}\n\n/** Reads the raw (pre node-mask-expansion) value payload: `count` values\n * (`count * components` scalars), each full width or half, through\n * blosc/zip/no compression (`io::readData` / `io::HalfReader::read`). */\nfunction readRawValues(\n reader: ByteReader,\n count: number,\n half: boolean,\n format: ValueFormat,\n compression: CompressionFlags,\n): Float32Array {\n const scalarBytes = half ? 2 : KIND_BYTES[format.kind];\n const elementSize = scalarBytes * format.components;\n\n const decodeBytes = (raw: Uint8Array, n: number): Float32Array => {\n if (raw.length < n * elementSize) {\n throw new VdbFormatError(`value payload is ${raw.length} bytes, expected ${n * elementSize}`);\n }\n return decodeScalars(raw, n * format.components, format.kind, half);\n };\n\n const readPlain = (n: number): Float32Array => decodeBytes(reader.bytes_(n * elementSize), n);\n\n /** The `<= 0` sentinel: raw values follow, `-n / elementSize` of them. */\n const readSentinelRaw = (numBytes: number): Float32Array => {\n const rawCount = -numBytes / elementSize;\n if (!Number.isInteger(rawCount) || rawCount < 0 || rawCount > count) {\n throw new VdbFormatError(\n `raw-value sentinel ${numBytes} is not a whole number of ${elementSize}-byte values within the expected ${count}`,\n );\n }\n return readPlain(rawCount);\n };\n\n if (compression.blosc) {\n const numCompressedBytes = readI64AsNumber(reader);\n if (numCompressedBytes <= 0) return readSentinelRaw(numCompressedBytes);\n // OpenVDB pads buffers shorter than Blosc's 48-byte minimum before\n // compressing, so the frame can decode to more than `count` values.\n const maxBytes = Math.max(count * elementSize, 48);\n const decoded = decompressBlosc(reader.bytes_(numCompressedBytes), {\n maxBytes,\n expectedCbytes: numCompressedBytes,\n });\n if (decoded.length < count * elementSize) {\n throw new VdbFormatError(`blosc frame decoded to ${decoded.length} bytes, expected ${count * elementSize}`);\n }\n return decodeBytes(decoded.subarray(0, count * elementSize), count);\n }\n\n if (compression.zip) {\n const numZippedBytes = readI64AsNumber(reader);\n if (numZippedBytes <= 0) return readSentinelRaw(numZippedBytes);\n const zippedBytes = reader.bytes_(numZippedBytes);\n const inflated = inflateZlib(zippedBytes, count * elementSize);\n return decodeBytes(inflated.subarray(0, count * elementSize), count);\n }\n\n return readPlain(count);\n}\n\n/** Reads a signed 64-bit stream field narrowed to `number` (compressed byte\n * counts are written as `int64_t` and can legitimately be <= 0 as a\n * \"not worth compressing, here's the raw size instead\" sentinel). */\nfunction readI64AsNumber(reader: ByteReader): number {\n const bytes = reader.bytes_(8);\n const view = new DataView(bytes.buffer, bytes.byteOffset, 8);\n const v = view.getBigInt64(0, true);\n if (v > BigInt(Number.MAX_SAFE_INTEGER) || v < -BigInt(Number.MAX_SAFE_INTEGER)) {\n throw new VdbFormatError(`i64 value ${v} exceeds safe integer range`);\n }\n return Number(v);\n}\n\nexport interface ReadCompressedOptions {\n fileVersion: number;\n compression: CompressionFlags;\n /** The grid was saved as half float (honoured for real formats only). */\n useHalf: boolean;\n /** The grid background, `format.components` entries. */\n background: ArrayLike<number>;\n /** Full logical size of this node's value table (32768 / 4096 / 512). */\n numValues: number;\n valueMask: Uint32Array;\n /** Value layout. Default: {@link FLOAT_FORMAT}. */\n format?: ValueFormat;\n}\n\n/** The generic \"node value array\" reader — used for internal-node tile\n * values (Node5/Node4) and leaf voxel values alike; both go through the\n * same on-disk encoding (`io::Compression::readCompressedValues`). Returns\n * `numValues * format.components` scalars. */\nexport function readCompressedValues(reader: ByteReader, opts: ReadCompressedOptions): Float32Array {\n const { fileVersion, compression, numValues, valueMask } = opts;\n const format = opts.format ?? FLOAT_FORMAT;\n const comps = format.components;\n const half = opts.useHalf && isRealFormat(format);\n\n let meta: NodeMetaData = NodeMetaData.NoMaskOrInactiveVals;\n if (fileVersion >= 222) {\n meta = reader.u8() as NodeMetaData;\n }\n\n // Inactive fill values, exactly as `io::readCompressedValues`:\n // inactiveVal1 = background\n // inactiveVal0 = (meta == NoMaskOrInactiveVals) ? background : -background\n // then one or two values read from the stream override them (written at\n // full `sizeof(ValueType)`, even for half-float grids). K4.8.\n const bg = Array.from({ length: comps }, (_, c) => opts.background[c]!);\n const negBg = bg.map((v) => -v);\n let inactiveVal0: ArrayLike<number> = meta === NodeMetaData.NoMaskOrInactiveVals ? bg : negBg;\n let inactiveVal1: ArrayLike<number> = bg;\n if (\n meta === NodeMetaData.NoMaskAndOneInactiveVal ||\n meta === NodeMetaData.MaskAndOneInactiveVal ||\n meta === NodeMetaData.MaskAndTwoInactiveVals\n ) {\n inactiveVal0 = readFullValue(reader, format);\n if (meta === NodeMetaData.MaskAndTwoInactiveVals) inactiveVal1 = readFullValue(reader, format);\n }\n\n let selectionMask: Uint32Array | null = null;\n if (\n meta === NodeMetaData.MaskAndNoInactiveVals ||\n meta === NodeMetaData.MaskAndOneInactiveVal ||\n meta === NodeMetaData.MaskAndTwoInactiveVals\n ) {\n selectionMask = reader.maskWords(numValues);\n }\n\n const onDiskCount =\n compression.activeMask && meta !== NodeMetaData.NoMaskAndAllVals && fileVersion >= 222\n ? countBits(valueMask)\n : numValues;\n\n // K4.7: `io::HalfReader<true, T>::read` returns before touching the stream\n // when `count < 1`, because `HalfWriter<true, T>::write` writes nothing for\n // an empty array, not even the blosc/zip size field. So a half-float node\n // whose mask compression leaves no values (an internal node without active\n // tiles, typically) has no payload at all. Full-width and integer arrays go\n // through plain `readData`, which still reads the size field for count 0.\n const raw =\n half && onDiskCount < 1 ? new Float32Array(0) : readRawValues(reader, onDiskCount, half, format, compression);\n\n if (raw.length !== onDiskCount * comps) {\n throw new VdbFormatError(`node value payload holds ${raw.length / comps} values, expected ${onDiskCount}`);\n }\n\n if (compression.activeMask && onDiskCount !== numValues) {\n const expanded = new Float32Array(numValues * comps);\n let readIdx = 0;\n if (comps === 1) {\n const fill0 = inactiveVal0[0]!;\n const fill1 = inactiveVal1[0]!;\n for (let i = 0; i < numValues; i++) {\n if (testBit(valueMask, i)) expanded[i] = raw[readIdx++]!;\n else expanded[i] = selectionMask && testBit(selectionMask, i) ? fill1 : fill0;\n }\n return expanded;\n }\n for (let i = 0; i < numValues; i++) {\n let src: ArrayLike<number> = inactiveVal0;\n let srcBase = 0;\n if (testBit(valueMask, i)) {\n src = raw;\n srcBase = readIdx++ * comps;\n } else if (selectionMask && testBit(selectionMask, i)) {\n src = inactiveVal1;\n }\n for (let c = 0; c < comps; c++) expanded[i * comps + c] = src[srcBase + c]!;\n }\n return expanded;\n }\n\n return raw;\n}\n"]}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * errors.ts — the `.vdb` parser's errors, from the tools' one hierarchy (`../errors.ts`, D32).
3
+ *
4
+ * `VdbFormatError` is for things that mean "this isn't a valid/parseable VDB
5
+ * stream at all" (bad magic, truncated buffer, corrupt masks). `VDBUnsupportedError`
6
+ * is for "this is a real VDB construct, but out of this parser's scope" (blosc
7
+ * codecs, tiles, non-5-4-3 trees, rotated transforms, ...) — per SPEC's
8
+ * "throw clear errors" contract.
9
+ */
10
+ export { VdbFormatError, VDBUnsupportedError } from "../errors.js";
@@ -0,0 +1,11 @@
1
+ /**
2
+ * errors.ts — the `.vdb` parser's errors, from the tools' one hierarchy (`../errors.ts`, D32).
3
+ *
4
+ * `VdbFormatError` is for things that mean "this isn't a valid/parseable VDB
5
+ * stream at all" (bad magic, truncated buffer, corrupt masks). `VDBUnsupportedError`
6
+ * is for "this is a real VDB construct, but out of this parser's scope" (blosc
7
+ * codecs, tiles, non-5-4-3 trees, rotated transforms, ...) — per SPEC's
8
+ * "throw clear errors" contract.
9
+ */
10
+ export { VdbFormatError, VDBUnsupportedError } from "../errors.js";
11
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/tools/vdb/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC","sourcesContent":["/**\n * errors.ts — the `.vdb` parser's errors, from the tools' one hierarchy (`../errors.ts`, D32).\n *\n * `VdbFormatError` is for things that mean \"this isn't a valid/parseable VDB\n * stream at all\" (bad magic, truncated buffer, corrupt masks). `VDBUnsupportedError`\n * is for \"this is a real VDB construct, but out of this parser's scope\" (blosc\n * codecs, tiles, non-5-4-3 trees, rotated transforms, ...) — per SPEC's\n * \"throw clear errors\" contract.\n */\nexport { VdbFormatError, VDBUnsupportedError } from \"../errors.js\";\n"]}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * grid.ts — the parsed `VdbGrid`: a flat leaf table and a flat active-tile
3
+ * table, each with O(1) lookup by (rounded-down) origin, backing
4
+ * `readValue`/`iterLeaves`/`iterTiles`.
5
+ *
6
+ * `readValue` resolves a coordinate the way an OpenVDB accessor would for the
7
+ * data this parser keeps: a stored leaf first, then an enclosing active tile
8
+ * (lower 8^3, upper 128^3, root 4096^3), then the background. Inactive tiles
9
+ * with a stored non-background value (e.g. a level set's interior
10
+ * `-background`) are kept and read back with `active: false` (K4.9).
11
+ *
12
+ * Values have `components` scalars (1, or 3 for vector grids, xyz
13
+ * interleaved in the leaf arrays); vector values come back as `[x, y, z]`.
14
+ */
15
+ import { type PointLeafData } from "./points.js";
16
+ import type { LeafData, TileData } from "./tree.js";
17
+ import type { VdbBBox, VdbGrid, VdbTransformInfo, VdbValueType } from "./types.js";
18
+ export interface GridInit {
19
+ name: string;
20
+ gridType: string;
21
+ valueType: VdbValueType;
22
+ transform: VdbTransformInfo;
23
+ metadata: Record<string, unknown>;
24
+ indexBBox: VdbBBox | null;
25
+ activeVoxelCount: number;
26
+ /** `components` scalars. */
27
+ background: number[];
28
+ leaves: LeafData[];
29
+ /** Active tiles; omitted means none. */
30
+ tiles?: TileData[];
31
+ /** Point data grids: per-leaf attribute data. */
32
+ pointLeaves?: PointLeafData[];
33
+ /** Point data grids: the most `points()` may allocate. Default: unlimited. */
34
+ pointOutputBudget?: number;
35
+ }
36
+ /** Builds the public grid object for the parsed data. */
37
+ export declare function createVdbGrid(init: GridInit): VdbGrid;