@pmndrs/vdb 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (390) hide show
  1. package/CHANGELOG.md +137 -0
  2. package/LICENSE +21 -0
  3. package/README.md +448 -2
  4. package/THIRD_PARTY_NOTICES.md +147 -0
  5. package/dist/core/compute/atlas.d.ts +94 -0
  6. package/dist/core/compute/atlas.js +98 -0
  7. package/dist/core/compute/atlas.js.map +1 -0
  8. package/dist/core/compute/index.d.ts +13 -0
  9. package/dist/core/compute/index.js +9 -0
  10. package/dist/core/compute/index.js.map +1 -0
  11. package/dist/core/compute/pyramid.d.ts +105 -0
  12. package/dist/core/compute/pyramid.js +455 -0
  13. package/dist/core/compute/pyramid.js.map +1 -0
  14. package/dist/core/compute/shared.d.ts +115 -0
  15. package/dist/core/compute/shared.js +211 -0
  16. package/dist/core/compute/shared.js.map +1 -0
  17. package/dist/core/compute/stats.d.ts +71 -0
  18. package/dist/core/compute/stats.js +188 -0
  19. package/dist/core/compute/stats.js.map +1 -0
  20. package/dist/core/compute/value-transform.d.ts +23 -0
  21. package/dist/core/compute/value-transform.js +58 -0
  22. package/dist/core/compute/value-transform.js.map +1 -0
  23. package/dist/core/errors.d.ts +11 -0
  24. package/dist/core/errors.js +9 -0
  25. package/dist/core/errors.js.map +1 -0
  26. package/dist/core/index.d.ts +30 -0
  27. package/dist/core/index.js +27 -0
  28. package/dist/core/index.js.map +1 -0
  29. package/dist/core/internal.d.ts +15 -0
  30. package/dist/core/internal.js +15 -0
  31. package/dist/core/internal.js.map +1 -0
  32. package/dist/core/pool/affine.d.ts +34 -0
  33. package/dist/core/pool/affine.js +100 -0
  34. package/dist/core/pool/affine.js.map +1 -0
  35. package/dist/core/pool/allocator.d.ts +32 -0
  36. package/dist/core/pool/allocator.js +81 -0
  37. package/dist/core/pool/allocator.js.map +1 -0
  38. package/dist/core/pool/image-header.d.ts +82 -0
  39. package/dist/core/pool/image-header.js +175 -0
  40. package/dist/core/pool/image-header.js.map +1 -0
  41. package/dist/core/pool/layout.d.ts +164 -0
  42. package/dist/core/pool/layout.js +267 -0
  43. package/dist/core/pool/layout.js.map +1 -0
  44. package/dist/core/pool/limits.d.ts +40 -0
  45. package/dist/core/pool/limits.js +79 -0
  46. package/dist/core/pool/limits.js.map +1 -0
  47. package/dist/core/pool/pool.d.ts +279 -0
  48. package/dist/core/pool/pool.js +953 -0
  49. package/dist/core/pool/pool.js.map +1 -0
  50. package/dist/core/source/dense.d.ts +19 -0
  51. package/dist/core/source/dense.js +287 -0
  52. package/dist/core/source/dense.js.map +1 -0
  53. package/dist/core/source/types.d.ts +63 -0
  54. package/dist/core/source/types.js +9 -0
  55. package/dist/core/source/types.js.map +1 -0
  56. package/dist/core/types.d.ts +28 -0
  57. package/dist/core/types.js +28 -0
  58. package/dist/core/types.js.map +1 -0
  59. package/dist/core/wgsl/api.d.ts +41 -0
  60. package/dist/core/wgsl/api.js +463 -0
  61. package/dist/core/wgsl/api.js.map +1 -0
  62. package/dist/core/wgsl/generate.d.ts +82 -0
  63. package/dist/core/wgsl/generate.js +505 -0
  64. package/dist/core/wgsl/generate.js.map +1 -0
  65. package/dist/core/wgsl/level-set.d.ts +54 -0
  66. package/dist/core/wgsl/level-set.js +194 -0
  67. package/dist/core/wgsl/level-set.js.map +1 -0
  68. package/dist/core/wgsl/pnanovdb.chunks.generated.d.ts +14 -0
  69. package/dist/core/wgsl/pnanovdb.chunks.generated.js +330 -0
  70. package/dist/core/wgsl/pnanovdb.chunks.generated.js.map +1 -0
  71. package/dist/core/wgsl/reserved.d.ts +9 -0
  72. package/dist/core/wgsl/reserved.js +26 -0
  73. package/dist/core/wgsl/reserved.js.map +1 -0
  74. package/dist/core/wgsl/types.d.ts +104 -0
  75. package/dist/core/wgsl/types.js +2 -0
  76. package/dist/core/wgsl/types.js.map +1 -0
  77. package/dist/three/coarse-first.d.ts +162 -0
  78. package/dist/three/coarse-first.js +187 -0
  79. package/dist/three/coarse-first.js.map +1 -0
  80. package/dist/three/compute.d.ts +63 -0
  81. package/dist/three/compute.js +56 -0
  82. package/dist/three/compute.js.map +1 -0
  83. package/dist/three/device.d.ts +59 -0
  84. package/dist/three/device.js +59 -0
  85. package/dist/three/device.js.map +1 -0
  86. package/dist/three/frame/blackbody.d.ts +42 -0
  87. package/dist/three/frame/blackbody.js +74 -0
  88. package/dist/three/frame/blackbody.js.map +1 -0
  89. package/dist/three/frame/chunks.d.ts +157 -0
  90. package/dist/three/frame/chunks.js +559 -0
  91. package/dist/three/frame/chunks.js.map +1 -0
  92. package/dist/three/frame/density-material.d.ts +53 -0
  93. package/dist/three/frame/density-material.js +353 -0
  94. package/dist/three/frame/density-material.js.map +1 -0
  95. package/dist/three/frame/emission-light.d.ts +167 -0
  96. package/dist/three/frame/emission-light.js +655 -0
  97. package/dist/three/frame/emission-light.js.map +1 -0
  98. package/dist/three/frame/environment-grid-material.d.ts +21 -0
  99. package/dist/three/frame/environment-grid-material.js +184 -0
  100. package/dist/three/frame/environment-grid-material.js.map +1 -0
  101. package/dist/three/frame/environment-material.d.ts +22 -0
  102. package/dist/three/frame/environment-material.js +87 -0
  103. package/dist/three/frame/environment-material.js.map +1 -0
  104. package/dist/three/frame/grid-mip-material.d.ts +12 -0
  105. package/dist/three/frame/grid-mip-material.js +61 -0
  106. package/dist/three/frame/grid-mip-material.js.map +1 -0
  107. package/dist/three/frame/index.d.ts +39 -0
  108. package/dist/three/frame/index.js +35 -0
  109. package/dist/three/frame/index.js.map +1 -0
  110. package/dist/three/frame/inject-material.d.ts +56 -0
  111. package/dist/three/frame/inject-material.js +424 -0
  112. package/dist/three/frame/inject-material.js.map +1 -0
  113. package/dist/three/frame/integrate-material.d.ts +26 -0
  114. package/dist/three/frame/integrate-material.js +198 -0
  115. package/dist/three/frame/integrate-material.js.map +1 -0
  116. package/dist/three/frame/layout.d.ts +34 -0
  117. package/dist/three/frame/layout.js +48 -0
  118. package/dist/three/frame/layout.js.map +1 -0
  119. package/dist/three/frame/lighting-material.d.ts +41 -0
  120. package/dist/three/frame/lighting-material.js +257 -0
  121. package/dist/three/frame/lighting-material.js.map +1 -0
  122. package/dist/three/frame/lights.d.ts +11 -0
  123. package/dist/three/frame/lights.js +16 -0
  124. package/dist/three/frame/lights.js.map +1 -0
  125. package/dist/three/frame/medium.d.ts +21 -0
  126. package/dist/three/frame/medium.js +29 -0
  127. package/dist/three/frame/medium.js.map +1 -0
  128. package/dist/three/frame/neural.d.ts +14 -0
  129. package/dist/three/frame/neural.js +105 -0
  130. package/dist/three/frame/neural.js.map +1 -0
  131. package/dist/three/frame/phase.d.ts +44 -0
  132. package/dist/three/frame/phase.js +80 -0
  133. package/dist/three/frame/phase.js.map +1 -0
  134. package/dist/three/frame/renderer.d.ts +493 -0
  135. package/dist/three/frame/renderer.js +1498 -0
  136. package/dist/three/frame/renderer.js.map +1 -0
  137. package/dist/three/frame/shadow-density-material.d.ts +30 -0
  138. package/dist/three/frame/shadow-density-material.js +123 -0
  139. package/dist/three/frame/shadow-density-material.js.map +1 -0
  140. package/dist/three/frame/spectrum.d.ts +18 -0
  141. package/dist/three/frame/spectrum.js +36 -0
  142. package/dist/three/frame/spectrum.js.map +1 -0
  143. package/dist/three/frame/temporal-material.d.ts +29 -0
  144. package/dist/three/frame/temporal-material.js +152 -0
  145. package/dist/three/frame/temporal-material.js.map +1 -0
  146. package/dist/three/frame/three-internals.d.ts +65 -0
  147. package/dist/three/frame/three-internals.js +150 -0
  148. package/dist/three/frame/three-internals.js.map +1 -0
  149. package/dist/three/frame/transmittance-material.d.ts +31 -0
  150. package/dist/three/frame/transmittance-material.js +315 -0
  151. package/dist/three/frame/transmittance-material.js.map +1 -0
  152. package/dist/three/frame/view.d.ts +103 -0
  153. package/dist/three/frame/view.js +296 -0
  154. package/dist/three/frame/view.js.map +1 -0
  155. package/dist/three/frame/volume-shadow-material.d.ts +36 -0
  156. package/dist/three/frame/volume-shadow-material.js +128 -0
  157. package/dist/three/frame/volume-shadow-material.js.map +1 -0
  158. package/dist/three/frame/volume-shadows.d.ts +153 -0
  159. package/dist/three/frame/volume-shadows.js +756 -0
  160. package/dist/three/frame/volume-shadows.js.map +1 -0
  161. package/dist/three/frame/volume.d.ts +172 -0
  162. package/dist/three/frame/volume.js +256 -0
  163. package/dist/three/frame/volume.js.map +1 -0
  164. package/dist/three/grid-node.d.ts +196 -0
  165. package/dist/three/grid-node.js +510 -0
  166. package/dist/three/grid-node.js.map +1 -0
  167. package/dist/three/index.d.ts +43 -0
  168. package/dist/three/index.js +49 -0
  169. package/dist/three/index.js.map +1 -0
  170. package/dist/three/internal.d.ts +14 -0
  171. package/dist/three/internal.js +14 -0
  172. package/dist/three/internal.js.map +1 -0
  173. package/dist/three/level-set-material.d.ts +112 -0
  174. package/dist/three/level-set-material.js +204 -0
  175. package/dist/three/level-set-material.js.map +1 -0
  176. package/dist/three/material.d.ts +194 -0
  177. package/dist/three/material.js +359 -0
  178. package/dist/three/material.js.map +1 -0
  179. package/dist/three/points.d.ts +84 -0
  180. package/dist/three/points.js +130 -0
  181. package/dist/three/points.js.map +1 -0
  182. package/dist/three/sequence.d.ts +317 -0
  183. package/dist/three/sequence.js +526 -0
  184. package/dist/three/sequence.js.map +1 -0
  185. package/dist/three/sparse-source.d.ts +233 -0
  186. package/dist/three/sparse-source.js +876 -0
  187. package/dist/three/sparse-source.js.map +1 -0
  188. package/dist/three/volume-source.d.ts +167 -0
  189. package/dist/three/volume-source.js +353 -0
  190. package/dist/three/volume-source.js.map +1 -0
  191. package/dist/tools/cpu/compute.d.ts +97 -0
  192. package/dist/tools/cpu/compute.js +218 -0
  193. package/dist/tools/cpu/compute.js.map +1 -0
  194. package/dist/tools/cpu/level-set.d.ts +72 -0
  195. package/dist/tools/cpu/level-set.js +261 -0
  196. package/dist/tools/cpu/level-set.js.map +1 -0
  197. package/dist/tools/cpu/march.d.ts +206 -0
  198. package/dist/tools/cpu/march.js +575 -0
  199. package/dist/tools/cpu/march.js.map +1 -0
  200. package/dist/tools/cpu/probe-coords.d.ts +70 -0
  201. package/dist/tools/cpu/probe-coords.js +116 -0
  202. package/dist/tools/cpu/probe-coords.js.map +1 -0
  203. package/dist/tools/cpu/read-value.d.ts +31 -0
  204. package/dist/tools/cpu/read-value.js +336 -0
  205. package/dist/tools/cpu/read-value.js.map +1 -0
  206. package/dist/tools/cpu/sample-trilinear.d.ts +30 -0
  207. package/dist/tools/cpu/sample-trilinear.js +156 -0
  208. package/dist/tools/cpu/sample-trilinear.js.map +1 -0
  209. package/dist/tools/cpu/stride-tables.d.ts +56 -0
  210. package/dist/tools/cpu/stride-tables.generated.d.ts +1058 -0
  211. package/dist/tools/cpu/stride-tables.generated.js +1266 -0
  212. package/dist/tools/cpu/stride-tables.generated.js.map +1 -0
  213. package/dist/tools/cpu/stride-tables.js +78 -0
  214. package/dist/tools/cpu/stride-tables.js.map +1 -0
  215. package/dist/tools/errors.d.ts +57 -0
  216. package/dist/tools/errors.js +58 -0
  217. package/dist/tools/errors.js.map +1 -0
  218. package/dist/tools/frame/blackbody.d.ts +42 -0
  219. package/dist/tools/frame/blackbody.js +116 -0
  220. package/dist/tools/frame/blackbody.js.map +1 -0
  221. package/dist/tools/frame/emission.d.ts +128 -0
  222. package/dist/tools/frame/emission.js +282 -0
  223. package/dist/tools/frame/emission.js.map +1 -0
  224. package/dist/tools/frame/environment.d.ts +105 -0
  225. package/dist/tools/frame/environment.js +268 -0
  226. package/dist/tools/frame/environment.js.map +1 -0
  227. package/dist/tools/frame/grid.d.ts +302 -0
  228. package/dist/tools/frame/grid.js +703 -0
  229. package/dist/tools/frame/grid.js.map +1 -0
  230. package/dist/tools/frame/index.d.ts +136 -0
  231. package/dist/tools/frame/index.js +348 -0
  232. package/dist/tools/frame/index.js.map +1 -0
  233. package/dist/tools/frame/medium.d.ts +61 -0
  234. package/dist/tools/frame/medium.js +99 -0
  235. package/dist/tools/frame/medium.js.map +1 -0
  236. package/dist/tools/frame/mie-table.d.ts +6 -0
  237. package/dist/tools/frame/mie-table.js +16 -0
  238. package/dist/tools/frame/mie-table.js.map +1 -0
  239. package/dist/tools/frame/mie.d.ts +54 -0
  240. package/dist/tools/frame/mie.js +176 -0
  241. package/dist/tools/frame/mie.js.map +1 -0
  242. package/dist/tools/frame/neural-weights.d.ts +9 -0
  243. package/dist/tools/frame/neural-weights.js +245 -0
  244. package/dist/tools/frame/neural-weights.js.map +1 -0
  245. package/dist/tools/frame/neural.d.ts +80 -0
  246. package/dist/tools/frame/neural.js +150 -0
  247. package/dist/tools/frame/neural.js.map +1 -0
  248. package/dist/tools/frame/pyramid-layout.d.ts +38 -0
  249. package/dist/tools/frame/pyramid-layout.js +53 -0
  250. package/dist/tools/frame/pyramid-layout.js.map +1 -0
  251. package/dist/tools/frame/shadows.d.ts +80 -0
  252. package/dist/tools/frame/shadows.js +182 -0
  253. package/dist/tools/frame/shadows.js.map +1 -0
  254. package/dist/tools/frame/sparse.d.ts +65 -0
  255. package/dist/tools/frame/sparse.js +191 -0
  256. package/dist/tools/frame/sparse.js.map +1 -0
  257. package/dist/tools/frame/spectral.d.ts +203 -0
  258. package/dist/tools/frame/spectral.js +550 -0
  259. package/dist/tools/frame/spectral.js.map +1 -0
  260. package/dist/tools/index.d.ts +106 -0
  261. package/dist/tools/index.js +88 -0
  262. package/dist/tools/index.js.map +1 -0
  263. package/dist/tools/internal.d.ts +46 -0
  264. package/dist/tools/internal.js +31 -0
  265. package/dist/tools/internal.js.map +1 -0
  266. package/dist/tools/nanovdb/build-from-vdb.d.ts +50 -0
  267. package/dist/tools/nanovdb/build-from-vdb.js +92 -0
  268. package/dist/tools/nanovdb/build-from-vdb.js.map +1 -0
  269. package/dist/tools/nanovdb/bytes.d.ts +220 -0
  270. package/dist/tools/nanovdb/bytes.js +345 -0
  271. package/dist/tools/nanovdb/bytes.js.map +1 -0
  272. package/dist/tools/nanovdb/coarse-first.d.ts +62 -0
  273. package/dist/tools/nanovdb/coarse-first.js +86 -0
  274. package/dist/tools/nanovdb/coarse-first.js.map +1 -0
  275. package/dist/tools/nanovdb/index.d.ts +32 -0
  276. package/dist/tools/nanovdb/index.js +24 -0
  277. package/dist/tools/nanovdb/index.js.map +1 -0
  278. package/dist/tools/nanovdb/inspect.d.ts +24 -0
  279. package/dist/tools/nanovdb/inspect.js +63 -0
  280. package/dist/tools/nanovdb/inspect.js.map +1 -0
  281. package/dist/tools/nanovdb/leaf-codec.d.ts +85 -0
  282. package/dist/tools/nanovdb/leaf-codec.js +320 -0
  283. package/dist/tools/nanovdb/leaf-codec.js.map +1 -0
  284. package/dist/tools/nanovdb/quantize.d.ts +43 -0
  285. package/dist/tools/nanovdb/quantize.js +277 -0
  286. package/dist/tools/nanovdb/quantize.js.map +1 -0
  287. package/dist/tools/nanovdb/resample.d.ts +160 -0
  288. package/dist/tools/nanovdb/resample.js +679 -0
  289. package/dist/tools/nanovdb/resample.js.map +1 -0
  290. package/dist/tools/nanovdb/serialize.d.ts +145 -0
  291. package/dist/tools/nanovdb/serialize.js +395 -0
  292. package/dist/tools/nanovdb/serialize.js.map +1 -0
  293. package/dist/tools/nanovdb/stats.d.ts +58 -0
  294. package/dist/tools/nanovdb/stats.js +149 -0
  295. package/dist/tools/nanovdb/stats.js.map +1 -0
  296. package/dist/tools/nanovdb/transform.d.ts +26 -0
  297. package/dist/tools/nanovdb/transform.js +91 -0
  298. package/dist/tools/nanovdb/transform.js.map +1 -0
  299. package/dist/tools/nanovdb/tree.d.ts +175 -0
  300. package/dist/tools/nanovdb/tree.js +518 -0
  301. package/dist/tools/nanovdb/tree.js.map +1 -0
  302. package/dist/tools/nanovdb/write-nvdb.d.ts +39 -0
  303. package/dist/tools/nanovdb/write-nvdb.js +210 -0
  304. package/dist/tools/nanovdb/write-nvdb.js.map +1 -0
  305. package/dist/tools/nvdb-file.d.ts +195 -0
  306. package/dist/tools/nvdb-file.js +606 -0
  307. package/dist/tools/nvdb-file.js.map +1 -0
  308. package/dist/tools/nvdb-stream.d.ts +138 -0
  309. package/dist/tools/nvdb-stream.js +365 -0
  310. package/dist/tools/nvdb-stream.js.map +1 -0
  311. package/dist/tools/vdb/bit-utils.d.ts +20 -0
  312. package/dist/tools/vdb/bit-utils.js +42 -0
  313. package/dist/tools/vdb/bit-utils.js.map +1 -0
  314. package/dist/tools/vdb/blosc.d.ts +56 -0
  315. package/dist/tools/vdb/blosc.js +231 -0
  316. package/dist/tools/vdb/blosc.js.map +1 -0
  317. package/dist/tools/vdb/byte-reader.d.ts +40 -0
  318. package/dist/tools/vdb/byte-reader.js +139 -0
  319. package/dist/tools/vdb/byte-reader.js.map +1 -0
  320. package/dist/tools/vdb/compression.d.ts +73 -0
  321. package/dist/tools/vdb/compression.js +249 -0
  322. package/dist/tools/vdb/compression.js.map +1 -0
  323. package/dist/tools/vdb/errors.d.ts +10 -0
  324. package/dist/tools/vdb/errors.js +11 -0
  325. package/dist/tools/vdb/errors.js.map +1 -0
  326. package/dist/tools/vdb/grid.d.ts +37 -0
  327. package/dist/tools/vdb/grid.js +147 -0
  328. package/dist/tools/vdb/grid.js.map +1 -0
  329. package/dist/tools/vdb/half-float.d.ts +9 -0
  330. package/dist/tools/vdb/half-float.js +24 -0
  331. package/dist/tools/vdb/half-float.js.map +1 -0
  332. package/dist/tools/vdb/index.d.ts +3 -0
  333. package/dist/tools/vdb/index.js +3 -0
  334. package/dist/tools/vdb/index.js.map +1 -0
  335. package/dist/tools/vdb/inflate.d.ts +24 -0
  336. package/dist/tools/vdb/inflate.js +334 -0
  337. package/dist/tools/vdb/inflate.js.map +1 -0
  338. package/dist/tools/vdb/metadata.d.ts +17 -0
  339. package/dist/tools/vdb/metadata.js +72 -0
  340. package/dist/tools/vdb/metadata.js.map +1 -0
  341. package/dist/tools/vdb/parse.d.ts +25 -0
  342. package/dist/tools/vdb/parse.js +171 -0
  343. package/dist/tools/vdb/parse.js.map +1 -0
  344. package/dist/tools/vdb/point-render-data.d.ts +31 -0
  345. package/dist/tools/vdb/point-render-data.js +57 -0
  346. package/dist/tools/vdb/point-render-data.js.map +1 -0
  347. package/dist/tools/vdb/points.d.ts +160 -0
  348. package/dist/tools/vdb/points.js +794 -0
  349. package/dist/tools/vdb/points.js.map +1 -0
  350. package/dist/tools/vdb/transform.d.ts +23 -0
  351. package/dist/tools/vdb/transform.js +54 -0
  352. package/dist/tools/vdb/transform.js.map +1 -0
  353. package/dist/tools/vdb/tree.d.ts +111 -0
  354. package/dist/tools/vdb/tree.js +228 -0
  355. package/dist/tools/vdb/tree.js.map +1 -0
  356. package/dist/tools/vdb/types.d.ts +138 -0
  357. package/dist/tools/vdb/types.js +3 -0
  358. package/dist/tools/vdb/types.js.map +1 -0
  359. package/dist/tools/wvdb/bake.d.ts +116 -0
  360. package/dist/tools/wvdb/bake.js +311 -0
  361. package/dist/tools/wvdb/bake.js.map +1 -0
  362. package/dist/tools/wvdb/dense.d.ts +112 -0
  363. package/dist/tools/wvdb/dense.js +309 -0
  364. package/dist/tools/wvdb/dense.js.map +1 -0
  365. package/dist/tools/wvdb/format.d.ts +161 -0
  366. package/dist/tools/wvdb/format.js +303 -0
  367. package/dist/tools/wvdb/format.js.map +1 -0
  368. package/dist/tools/wvdb/index.d.ts +13 -0
  369. package/dist/tools/wvdb/index.js +14 -0
  370. package/dist/tools/wvdb/index.js.map +1 -0
  371. package/dist/tools/wvdb/level-set.d.ts +48 -0
  372. package/dist/tools/wvdb/level-set.js +153 -0
  373. package/dist/tools/wvdb/level-set.js.map +1 -0
  374. package/dist/tools/wvdb/nanovdb.d.ts +54 -0
  375. package/dist/tools/wvdb/nanovdb.js +60 -0
  376. package/dist/tools/wvdb/nanovdb.js.map +1 -0
  377. package/dist/tools/wvdb/read.d.ts +260 -0
  378. package/dist/tools/wvdb/read.js +743 -0
  379. package/dist/tools/wvdb/read.js.map +1 -0
  380. package/dist/tools/wvdb/sha256.d.ts +7 -0
  381. package/dist/tools/wvdb/sha256.js +76 -0
  382. package/dist/tools/wvdb/sha256.js.map +1 -0
  383. package/dist/tools/wvdb/write.d.ts +127 -0
  384. package/dist/tools/wvdb/write.js +396 -0
  385. package/dist/tools/wvdb/write.js.map +1 -0
  386. package/package.json +82 -4
  387. package/vendor/LICENSE +201 -0
  388. package/vendor/NOTICE +19 -0
  389. package/vendor/VENDOR.md +85 -0
  390. package/vendor/pnanovdb.wgsl +1539 -0
@@ -0,0 +1,17 @@
1
+ /**
2
+ * metadata.ts — the generic `(name, type, byteLength, value)` metadata map
3
+ * used both at file scope (`OpenVDBReader.readHeader`) and per-grid scope
4
+ * (`GridDescriptor.readMetadata`) — same on-disk encoding both times, per
5
+ * both format references.
6
+ */
7
+ import type { ByteReader } from "./byte-reader.js";
8
+ export type MetadataValue = string | boolean | number | bigint | [number, number, number] | Uint8Array;
9
+ /**
10
+ * Reads a `count`-prefixed `(name, type, len, value)*` metadata map.
11
+ *
12
+ * The result has a null prototype (K4.14): metadata names come from the file, and a
13
+ * name like `__proto__` must become an ordinary own key, never write through to a
14
+ * prototype. Use `Object.hasOwn` / `in` / `Object.keys`; `.hasOwnProperty` and
15
+ * `.toString` are not available on it.
16
+ */
17
+ export declare function readMetadataMap(reader: ByteReader): Record<string, MetadataValue>;
@@ -0,0 +1,72 @@
1
+ /**
2
+ * metadata.ts — the generic `(name, type, byteLength, value)` metadata map
3
+ * used both at file scope (`OpenVDBReader.readHeader`) and per-grid scope
4
+ * (`GridDescriptor.readMetadata`) — same on-disk encoding both times, per
5
+ * both format references.
6
+ */
7
+ function readMetadataValue(reader, type, byteLength) {
8
+ const start = reader.pos;
9
+ let value;
10
+ switch (type) {
11
+ case "string":
12
+ value = reader.fixedString(byteLength);
13
+ break;
14
+ case "bool":
15
+ value = reader.bool();
16
+ break;
17
+ case "int32":
18
+ value = reader.i32();
19
+ break;
20
+ case "int64":
21
+ value = reader.u64(); // stored/consumed as bigint; real files use plain magnitudes
22
+ break;
23
+ case "float":
24
+ value = reader.f32();
25
+ break;
26
+ case "double":
27
+ value = reader.f64();
28
+ break;
29
+ case "vec3i":
30
+ value = reader.vec3i();
31
+ break;
32
+ case "vec3s":
33
+ value = [reader.f32(), reader.f32(), reader.f32()];
34
+ break;
35
+ case "vec3d":
36
+ value = reader.vec3d();
37
+ break;
38
+ default:
39
+ // Unknown metadata type (e.g. exotic user metadata) — keep the raw
40
+ // bytes rather than failing the whole parse over cosmetic metadata.
41
+ value = reader.bytes_(byteLength).slice();
42
+ break;
43
+ }
44
+ const consumed = reader.pos - start;
45
+ if (consumed !== byteLength) {
46
+ // Some types (e.g. "string") legitimately consume exactly byteLength;
47
+ // fixed-size types should too. If not, trust the declared length so a
48
+ // format quirk here doesn't desync the rest of the stream.
49
+ reader.seek(start + byteLength);
50
+ }
51
+ return value;
52
+ }
53
+ /**
54
+ * Reads a `count`-prefixed `(name, type, len, value)*` metadata map.
55
+ *
56
+ * The result has a null prototype (K4.14): metadata names come from the file, and a
57
+ * name like `__proto__` must become an ordinary own key, never write through to a
58
+ * prototype. Use `Object.hasOwn` / `in` / `Object.keys`; `.hasOwnProperty` and
59
+ * `.toString` are not available on it.
60
+ */
61
+ export function readMetadataMap(reader) {
62
+ const count = reader.u32();
63
+ const map = Object.create(null);
64
+ for (let i = 0; i < count; i++) {
65
+ const name = reader.string();
66
+ const type = reader.string();
67
+ const byteLength = reader.u32();
68
+ map[name] = readMetadataValue(reader, type, byteLength);
69
+ }
70
+ return map;
71
+ }
72
+ //# sourceMappingURL=metadata.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metadata.js","sourceRoot":"","sources":["../../../src/tools/vdb/metadata.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAYH,SAAS,iBAAiB,CAAC,MAAkB,EAAE,IAAY,EAAE,UAAkB;IAC7E,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC;IACzB,IAAI,KAAoB,CAAC;IACzB,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,QAAQ;YACX,KAAK,GAAG,MAAM,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;YACvC,MAAM;QACR,KA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AC,IAAI,CAAkC,CAAC;IAChG,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;QAC/B,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;QAC7B,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;QAC7B,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,EAAE,CAAC;QAChC,GAAG,CAAC,IAAI,CAAC,GAAG,iBAAiB,CAAC,MAAM,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC;IAC1D,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["/**\n * metadata.ts — the generic `(name, type, byteLength, value)` metadata map\n * used both at file scope (`OpenVDBReader.readHeader`) and per-grid scope\n * (`GridDescriptor.readMetadata`) — same on-disk encoding both times, per\n * both format references.\n */\n\nimport type { ByteReader } from \"./byte-reader.js\";\n\nexport type MetadataValue =\n | string\n | boolean\n | number\n | bigint\n | [number, number, number]\n | Uint8Array;\n\nfunction readMetadataValue(reader: ByteReader, type: string, byteLength: number): MetadataValue {\n const start = reader.pos;\n let value: MetadataValue;\n switch (type) {\n case \"string\":\n value = reader.fixedString(byteLength);\n break;\n case \"bool\":\n value = reader.bool();\n break;\n case \"int32\":\n value = reader.i32();\n break;\n case \"int64\":\n value = reader.u64(); // stored/consumed as bigint; real files use plain magnitudes\n break;\n case \"float\":\n value = reader.f32();\n break;\n case \"double\":\n value = reader.f64();\n break;\n case \"vec3i\":\n value = reader.vec3i();\n break;\n case \"vec3s\":\n value = [reader.f32(), reader.f32(), reader.f32()];\n break;\n case \"vec3d\":\n value = reader.vec3d();\n break;\n default:\n // Unknown metadata type (e.g. exotic user metadata) — keep the raw\n // bytes rather than failing the whole parse over cosmetic metadata.\n value = reader.bytes_(byteLength).slice();\n break;\n }\n const consumed = reader.pos - start;\n if (consumed !== byteLength) {\n // Some types (e.g. \"string\") legitimately consume exactly byteLength;\n // fixed-size types should too. If not, trust the declared length so a\n // format quirk here doesn't desync the rest of the stream.\n reader.seek(start + byteLength);\n }\n return value;\n}\n\n/**\n * Reads a `count`-prefixed `(name, type, len, value)*` metadata map.\n *\n * The result has a null prototype (K4.14): metadata names come from the file, and a\n * name like `__proto__` must become an ordinary own key, never write through to a\n * prototype. Use `Object.hasOwn` / `in` / `Object.keys`; `.hasOwnProperty` and\n * `.toString` are not available on it.\n */\nexport function readMetadataMap(reader: ByteReader): Record<string, MetadataValue> {\n const count = reader.u32();\n const map: Record<string, MetadataValue> = Object.create(null) as Record<string, MetadataValue>;\n for (let i = 0; i < count; i++) {\n const name = reader.string();\n const type = reader.string();\n const byteLength = reader.u32();\n map[name] = readMetadataValue(reader, type, byteLength);\n }\n return map;\n}\n"]}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * parse.ts — top-level `.vdb` container reader (docs/archive/v1/SPEC.md §4).
3
+ *
4
+ * File layout (format facts cross-checked between `mjurczyk/openvdb`'s
5
+ * `OpenVDBReader`/`GridDescriptor` and `vdb-rs`'s `VdbReader::new`/
6
+ * `read_grid_descriptors`/`read_grid_internal`):
7
+ *
8
+ * magic(u64) file_version(u32) [lib_major(u32) lib_minor(u32)]
9
+ * has_grid_offsets(u8) [is_compressed(u8) if 220<=v<222] guid(36 chars)
10
+ * metadata_map grid_count(u32)
11
+ * grid_count x {
12
+ * unique_name type_name [instance_parent] grid_pos(u64) block_pos(u64) end_pos(u64)
13
+ * -- seek to grid_pos --
14
+ * [compression(u32) if v>=222] metadata_map transform tree_topology tree_buffers
15
+ * }
16
+ *
17
+ * Unlike both references' lazy/two-pass grid-descriptor tables (built for
18
+ * random access to a single named grid), `parseVdb` decodes every grid in
19
+ * one linear pass and defensively re-seeks to each descriptor's `end_pos`
20
+ * afterward — the `mjurczyk/openvdb` reader does the same "hack" for
21
+ * multi-grid files, and it's cheap insurance against any of our own
22
+ * byte-accounting bugs desyncing the stream for the next grid.
23
+ */
24
+ import type { VdbFile } from "./types.js";
25
+ export declare function parseVdb(buffer: ArrayBuffer): VdbFile;
@@ -0,0 +1,171 @@
1
+ /**
2
+ * parse.ts — top-level `.vdb` container reader (docs/archive/v1/SPEC.md §4).
3
+ *
4
+ * File layout (format facts cross-checked between `mjurczyk/openvdb`'s
5
+ * `OpenVDBReader`/`GridDescriptor` and `vdb-rs`'s `VdbReader::new`/
6
+ * `read_grid_descriptors`/`read_grid_internal`):
7
+ *
8
+ * magic(u64) file_version(u32) [lib_major(u32) lib_minor(u32)]
9
+ * has_grid_offsets(u8) [is_compressed(u8) if 220<=v<222] guid(36 chars)
10
+ * metadata_map grid_count(u32)
11
+ * grid_count x {
12
+ * unique_name type_name [instance_parent] grid_pos(u64) block_pos(u64) end_pos(u64)
13
+ * -- seek to grid_pos --
14
+ * [compression(u32) if v>=222] metadata_map transform tree_topology tree_buffers
15
+ * }
16
+ *
17
+ * Unlike both references' lazy/two-pass grid-descriptor tables (built for
18
+ * random access to a single named grid), `parseVdb` decodes every grid in
19
+ * one linear pass and defensively re-seeks to each descriptor's `end_pos`
20
+ * afterward — the `mjurczyk/openvdb` reader does the same "hack" for
21
+ * multi-grid files, and it's cheap insurance against any of our own
22
+ * byte-accounting bugs desyncing the stream for the next grid.
23
+ */
24
+ import { ByteReader } from "./byte-reader.js";
25
+ import { compressionFromBits, FLOAT_FORMAT, PTDATAIDX32_FORMAT, VEC3D_FORMAT, VEC3I_FORMAT, VEC3S_FORMAT, } from "./compression.js";
26
+ import { VdbFormatError, VDBUnsupportedError } from "./errors.js";
27
+ import { createVdbGrid } from "./grid.js";
28
+ import { readMetadataMap } from "./metadata.js";
29
+ import { readTransform } from "./transform.js";
30
+ import { readTree } from "./tree.js";
31
+ const MAGIC_LOW = 0x56444220; // 'V','D','B',' ' read little-endian, low 32 bits
32
+ const MIN_SUPPORTED_VERSION = 213; // OPENVDB_FILE_VERSION_ROOTNODE_MAP
33
+ const MAX_SUPPORTED_VERSION = 225; // OPENVDB_FILE_VERSION: OpenVDB rejects anything newer
34
+ const VERSION_GRID_INSTANCING = 216;
35
+ const VERSION_BOOST_UUID = 218;
36
+ const VERSION_SELECTIVE_COMPRESSION = 220;
37
+ const VERSION_NODE_MASK_COMPRESSION = 222;
38
+ const VERSION_BLOSC_COMPRESSION = 223;
39
+ const GRID_TYPE_RE = /^Tree_([A-Za-z0-9]+)_(\d+)_(\d+)_(\d+)$/;
40
+ /** Value types this parser reads, and their on-disk layout. */
41
+ const VALUE_FORMATS = {
42
+ float: FLOAT_FORMAT,
43
+ vec3s: VEC3S_FORMAT,
44
+ vec3d: VEC3D_FORMAT,
45
+ vec3i: VEC3I_FORMAT,
46
+ ptdataidx32: PTDATAIDX32_FORMAT,
47
+ };
48
+ function isSupportedValueType(t) {
49
+ return Object.prototype.hasOwnProperty.call(VALUE_FORMATS, t);
50
+ }
51
+ function readHeaderCompression(reader, fileVersion) {
52
+ let compression = { zip: false, activeMask: true, blosc: true }; // DEFAULT_COMPRESSION
53
+ if (fileVersion < VERSION_BLOSC_COMPRESSION) {
54
+ compression = { zip: true, activeMask: true, blosc: false };
55
+ }
56
+ if (fileVersion >= VERSION_SELECTIVE_COMPRESSION && fileVersion < VERSION_NODE_MASK_COMPRESSION) {
57
+ const isCompressed = reader.bool();
58
+ compression = isCompressed
59
+ ? { zip: true, activeMask: false, blosc: false }
60
+ : { zip: false, activeMask: false, blosc: false };
61
+ }
62
+ return compression;
63
+ }
64
+ function readBBoxFromMetadata(metadata) {
65
+ const min = metadata["file_bbox_min"];
66
+ const max = metadata["file_bbox_max"];
67
+ if (Array.isArray(min) && Array.isArray(max) && min.length === 3 && max.length === 3) {
68
+ return {
69
+ min: [min[0], min[1], min[2]],
70
+ max: [max[0], max[1], max[2]],
71
+ };
72
+ }
73
+ return null;
74
+ }
75
+ export function parseVdb(buffer) {
76
+ const reader = new ByteReader(buffer);
77
+ if (reader.length < 8) {
78
+ throw new VdbFormatError("buffer too short to contain the magic number");
79
+ }
80
+ const magicLow = reader.u32();
81
+ const magicHigh = reader.u32();
82
+ if (magicLow !== MAGIC_LOW || magicHigh !== 0) {
83
+ throw new VdbFormatError(`bad magic number (expected 0x${MAGIC_LOW.toString(16)}, got 0x${magicLow.toString(16)}) — not a .vdb file`);
84
+ }
85
+ const fileVersion = reader.u32();
86
+ if (fileVersion < MIN_SUPPORTED_VERSION) {
87
+ throw new VDBUnsupportedError(`file version ${fileVersion} is older than the minimum supported version ${MIN_SUPPORTED_VERSION}`);
88
+ }
89
+ if (fileVersion > MAX_SUPPORTED_VERSION) {
90
+ throw new VDBUnsupportedError(`file version ${fileVersion} is newer than the maximum supported version ${MAX_SUPPORTED_VERSION}`);
91
+ }
92
+ reader.u32(); // library version major (informational only)
93
+ reader.u32(); // library version minor (informational only)
94
+ const hasGridOffsets = reader.bool();
95
+ if (!hasGridOffsets) {
96
+ throw new VDBUnsupportedError("VDB streams without grid offsets are not supported");
97
+ }
98
+ const headerCompression = readHeaderCompression(reader, fileVersion);
99
+ if (fileVersion < VERSION_BOOST_UUID) {
100
+ throw new VDBUnsupportedError(`file version ${fileVersion} predates the Boost-UUID header layout (< 218)`);
101
+ }
102
+ reader.fixedString(36); // uuid (informational only)
103
+ readMetadataMap(reader); // file-level metadata (informational only)
104
+ const gridCount = reader.u32();
105
+ const grids = [];
106
+ for (let i = 0; i < gridCount; i++) {
107
+ const uniqueName = reader.string();
108
+ const name = uniqueName.split("\x1e")[0] ?? uniqueName;
109
+ let gridType = reader.string();
110
+ let savedAsHalfFloat = false;
111
+ if (gridType.includes("_HalfFloat")) {
112
+ savedAsHalfFloat = true;
113
+ gridType = gridType.split("_HalfFloat").join("");
114
+ }
115
+ let instanceParentName = "";
116
+ if (fileVersion >= VERSION_GRID_INSTANCING) {
117
+ instanceParentName = reader.string();
118
+ }
119
+ if (instanceParentName !== "") {
120
+ throw new VDBUnsupportedError(`grid "${name}": instanced grids (sharing another grid's tree) are not supported`);
121
+ }
122
+ const gridPos = reader.u64AsNumber();
123
+ const blockPos = reader.u64AsNumber();
124
+ void blockPos; // not needed: we read topology+buffers in one contiguous pass
125
+ const endPos = reader.u64AsNumber();
126
+ reader.seek(gridPos);
127
+ const compression = fileVersion >= VERSION_NODE_MASK_COMPRESSION
128
+ ? compressionFromBits(reader.u32())
129
+ : headerCompression;
130
+ const metadata = readMetadataMap(reader);
131
+ const useHalf = savedAsHalfFloat || metadata["is_saved_as_half_float"] === true;
132
+ const match = GRID_TYPE_RE.exec(gridType);
133
+ if (!match) {
134
+ throw new VDBUnsupportedError(`grid "${name}": unrecognized grid type "${gridType}" (expected "Tree_<valueType>_<log2dim>_<log2dim>_<log2dim>")`);
135
+ }
136
+ const [, valueType, d0, d1, d2] = match;
137
+ if (!isSupportedValueType(valueType)) {
138
+ throw new VDBUnsupportedError(`grid "${name}": value type "${valueType}" is not supported ` +
139
+ `(supported: ${Object.keys(VALUE_FORMATS).join(", ")})`);
140
+ }
141
+ if (d0 !== "5" || d1 !== "4" || d2 !== "3") {
142
+ throw new VDBUnsupportedError(`grid "${name}": tree configuration ${d0}-${d1}-${d2} is not supported (only the 5-4-3 tree is in scope)`);
143
+ }
144
+ const transform = readTransform(reader);
145
+ const { background, leaves, tiles, activeVoxelCount, pointLeaves, pointOutputBudget } = readTree(reader, {
146
+ fileVersion,
147
+ compression,
148
+ useHalf,
149
+ format: VALUE_FORMATS[valueType],
150
+ pointData: valueType === "ptdataidx32",
151
+ });
152
+ grids.push(createVdbGrid({
153
+ name,
154
+ gridType,
155
+ valueType,
156
+ transform,
157
+ metadata,
158
+ indexBBox: readBBoxFromMetadata(metadata),
159
+ activeVoxelCount,
160
+ background,
161
+ leaves,
162
+ tiles,
163
+ ...(pointLeaves ? { pointLeaves, pointOutputBudget } : {}),
164
+ }));
165
+ // Defensive re-sync (matches the `mjurczyk/openvdb` reader's own hack):
166
+ // land exactly on the next grid descriptor regardless of any drift.
167
+ reader.seek(endPos);
168
+ }
169
+ return { fileVersion, grids };
170
+ }
171
+ //# sourceMappingURL=parse.js.map
@@ -0,0 +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,IAAI,EAAE,qDAAqD,CAC1G,CAAC;QACJ,CAAC;QAED,MAAM,SAAS,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;QACxC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,iBAAiB,EAAE,GAAG,QAAQ,CAAC,MAAM,EAAE;YACvG,WAAW;YACX,WAAW;YACX,OAAO;YACP,MAAM,EAAE,aAAa,CAAC,SAAS,CAAC;YAChC,SAAS,EAAE,SAAS,KAAK,aAAa;SACvC,CAAC,CAAC;QAEH,KAAK,CAAC,IAAI,CACR,aAAa,CAAC;YACZ,IAAI;YACJ,QAAQ;YACR,SAAS;YACT,SAAS;YACT,QAAQ;YACR,SAAS,EAAE,oBAAoB,CAAC,QAAQ,CAAC;YACzC,gBAAgB;YAChB,UAAU;YACV,MAAM;YACN,KAAK;YACL,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,iBAAiB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC3D,CAAC,CACH,CAAC;QAEF,wEAAwE;QACxE,oEAAoE;QACpE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACtB,CAAC;IAED,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC;AAChC,CAAC","sourcesContent":["/**\n * parse.ts — top-level `.vdb` container reader (docs/archive/v1/SPEC.md §4).\n *\n * File layout (format facts cross-checked between `mjurczyk/openvdb`'s\n * `OpenVDBReader`/`GridDescriptor` and `vdb-rs`'s `VdbReader::new`/\n * `read_grid_descriptors`/`read_grid_internal`):\n *\n * magic(u64) file_version(u32) [lib_major(u32) lib_minor(u32)]\n * has_grid_offsets(u8) [is_compressed(u8) if 220<=v<222] guid(36 chars)\n * metadata_map grid_count(u32)\n * grid_count x {\n * unique_name type_name [instance_parent] grid_pos(u64) block_pos(u64) end_pos(u64)\n * -- seek to grid_pos --\n * [compression(u32) if v>=222] metadata_map transform tree_topology tree_buffers\n * }\n *\n * Unlike both references' lazy/two-pass grid-descriptor tables (built for\n * random access to a single named grid), `parseVdb` decodes every grid in\n * one linear pass and defensively re-seeks to each descriptor's `end_pos`\n * afterward — the `mjurczyk/openvdb` reader does the same \"hack\" for\n * multi-grid files, and it's cheap insurance against any of our own\n * byte-accounting bugs desyncing the stream for the next grid.\n */\n\nimport { ByteReader } from \"./byte-reader.js\";\nimport type { CompressionFlags, ValueFormat } from \"./compression.js\";\nimport {\n compressionFromBits,\n FLOAT_FORMAT,\n PTDATAIDX32_FORMAT,\n VEC3D_FORMAT,\n VEC3I_FORMAT,\n VEC3S_FORMAT,\n} from \"./compression.js\";\nimport { VdbFormatError, VDBUnsupportedError } from \"./errors.js\";\nimport { createVdbGrid } from \"./grid.js\";\nimport { readMetadataMap } from \"./metadata.js\";\nimport { readTransform } from \"./transform.js\";\nimport { readTree } from \"./tree.js\";\nimport type { VdbBBox, VdbFile, VdbGrid, VdbValueType } from \"./types.js\";\n\nconst MAGIC_LOW = 0x56444220; // 'V','D','B',' ' read little-endian, low 32 bits\nconst MIN_SUPPORTED_VERSION = 213; // OPENVDB_FILE_VERSION_ROOTNODE_MAP\nconst MAX_SUPPORTED_VERSION = 225; // OPENVDB_FILE_VERSION: OpenVDB rejects anything newer\nconst VERSION_GRID_INSTANCING = 216;\nconst VERSION_BOOST_UUID = 218;\nconst VERSION_SELECTIVE_COMPRESSION = 220;\nconst VERSION_NODE_MASK_COMPRESSION = 222;\nconst VERSION_BLOSC_COMPRESSION = 223;\n\nconst GRID_TYPE_RE = /^Tree_([A-Za-z0-9]+)_(\\d+)_(\\d+)_(\\d+)$/;\n\n/** Value types this parser reads, and their on-disk layout. */\nconst VALUE_FORMATS: Record<VdbValueType, ValueFormat> = {\n float: FLOAT_FORMAT,\n vec3s: VEC3S_FORMAT,\n vec3d: VEC3D_FORMAT,\n vec3i: VEC3I_FORMAT,\n ptdataidx32: PTDATAIDX32_FORMAT,\n};\n\nfunction isSupportedValueType(t: string): t is VdbValueType {\n return Object.prototype.hasOwnProperty.call(VALUE_FORMATS, t);\n}\n\nfunction readHeaderCompression(reader: ByteReader, fileVersion: number): CompressionFlags {\n let compression: CompressionFlags = { zip: false, activeMask: true, blosc: true }; // DEFAULT_COMPRESSION\n if (fileVersion < VERSION_BLOSC_COMPRESSION) {\n compression = { zip: true, activeMask: true, blosc: false };\n }\n if (fileVersion >= VERSION_SELECTIVE_COMPRESSION && fileVersion < VERSION_NODE_MASK_COMPRESSION) {\n const isCompressed = reader.bool();\n compression = isCompressed\n ? { zip: true, activeMask: false, blosc: false }\n : { zip: false, activeMask: false, blosc: false };\n }\n return compression;\n}\n\nfunction readBBoxFromMetadata(metadata: Record<string, unknown>): VdbBBox | null {\n const min = metadata[\"file_bbox_min\"];\n const max = metadata[\"file_bbox_max\"];\n if (Array.isArray(min) && Array.isArray(max) && min.length === 3 && max.length === 3) {\n return {\n min: [min[0], min[1], min[2]] as [number, number, number],\n max: [max[0], max[1], max[2]] as [number, number, number],\n };\n }\n return null;\n}\n\nexport function parseVdb(buffer: ArrayBuffer): VdbFile {\n const reader = new ByteReader(buffer);\n\n if (reader.length < 8) {\n throw new VdbFormatError(\"buffer too short to contain the magic number\");\n }\n const magicLow = reader.u32();\n const magicHigh = reader.u32();\n if (magicLow !== MAGIC_LOW || magicHigh !== 0) {\n throw new VdbFormatError(\n `bad magic number (expected 0x${MAGIC_LOW.toString(16)}, got 0x${magicLow.toString(16)}) — not a .vdb file`,\n );\n }\n\n const fileVersion = reader.u32();\n if (fileVersion < MIN_SUPPORTED_VERSION) {\n throw new VDBUnsupportedError(\n `file version ${fileVersion} is older than the minimum supported version ${MIN_SUPPORTED_VERSION}`,\n );\n }\n\n if (fileVersion > MAX_SUPPORTED_VERSION) {\n throw new VDBUnsupportedError(\n `file version ${fileVersion} is newer than the maximum supported version ${MAX_SUPPORTED_VERSION}`,\n );\n }\n\n reader.u32(); // library version major (informational only)\n reader.u32(); // library version minor (informational only)\n\n const hasGridOffsets = reader.bool();\n if (!hasGridOffsets) {\n throw new VDBUnsupportedError(\"VDB streams without grid offsets are not supported\");\n }\n\n const headerCompression = readHeaderCompression(reader, fileVersion);\n\n if (fileVersion < VERSION_BOOST_UUID) {\n throw new VDBUnsupportedError(`file version ${fileVersion} predates the Boost-UUID header layout (< 218)`);\n }\n reader.fixedString(36); // uuid (informational only)\n\n readMetadataMap(reader); // file-level metadata (informational only)\n\n const gridCount = reader.u32();\n const grids: VdbGrid[] = [];\n\n for (let i = 0; i < gridCount; i++) {\n const uniqueName = reader.string();\n const name = uniqueName.split(\"\\x1e\")[0] ?? uniqueName;\n let gridType = reader.string();\n\n let savedAsHalfFloat = false;\n if (gridType.includes(\"_HalfFloat\")) {\n savedAsHalfFloat = true;\n gridType = gridType.split(\"_HalfFloat\").join(\"\");\n }\n\n let instanceParentName = \"\";\n if (fileVersion >= VERSION_GRID_INSTANCING) {\n instanceParentName = reader.string();\n }\n if (instanceParentName !== \"\") {\n throw new VDBUnsupportedError(`grid \"${name}\": instanced grids (sharing another grid's tree) are not supported`);\n }\n\n const gridPos = reader.u64AsNumber();\n const blockPos = reader.u64AsNumber();\n void blockPos; // not needed: we read topology+buffers in one contiguous pass\n const endPos = reader.u64AsNumber();\n\n reader.seek(gridPos);\n\n const compression =\n fileVersion >= VERSION_NODE_MASK_COMPRESSION\n ? compressionFromBits(reader.u32())\n : headerCompression;\n\n const metadata = readMetadataMap(reader);\n const useHalf = savedAsHalfFloat || metadata[\"is_saved_as_half_float\"] === true;\n\n const match = GRID_TYPE_RE.exec(gridType);\n if (!match) {\n throw new VDBUnsupportedError(\n `grid \"${name}\": unrecognized grid type \"${gridType}\" (expected \"Tree_<valueType>_<log2dim>_<log2dim>_<log2dim>\")`,\n );\n }\n const [, valueType, d0, d1, d2] = match;\n if (!isSupportedValueType(valueType!)) {\n throw new VDBUnsupportedError(\n `grid \"${name}\": value type \"${valueType}\" is not supported ` +\n `(supported: ${Object.keys(VALUE_FORMATS).join(\", \")})`,\n );\n }\n if (d0 !== \"5\" || d1 !== \"4\" || d2 !== \"3\") {\n throw new VDBUnsupportedError(\n `grid \"${name}\": tree configuration ${d0}-${d1}-${d2} is not supported (only the 5-4-3 tree is in scope)`,\n );\n }\n\n const transform = readTransform(reader);\n const { background, leaves, tiles, activeVoxelCount, pointLeaves, pointOutputBudget } = readTree(reader, {\n fileVersion,\n compression,\n useHalf,\n format: VALUE_FORMATS[valueType],\n pointData: valueType === \"ptdataidx32\",\n });\n\n grids.push(\n createVdbGrid({\n name,\n gridType,\n valueType,\n transform,\n metadata,\n indexBBox: readBBoxFromMetadata(metadata),\n activeVoxelCount,\n background,\n leaves,\n tiles,\n ...(pointLeaves ? { pointLeaves, pointOutputBudget } : {}),\n }),\n );\n\n // Defensive re-sync (matches the `mjurczyk/openvdb` reader's own hack):\n // land exactly on the next grid descriptor regardless of any drift.\n reader.seek(endPos);\n }\n\n return { fileVersion, grids };\n}\n"]}
@@ -0,0 +1,31 @@
1
+ import type { VdbPointDataGrid } from "./types.js";
2
+ /** What `VDBPoints` draws: world positions (xyz per point), optional linear RGB, the mean spacing. */
3
+ export interface VDBPointRenderData {
4
+ /** Points in the arrays. */
5
+ count: number;
6
+ /** Points in the grid before the stride. */
7
+ totalCount: number;
8
+ /** Every `stride`-th point (in the grid's point order) is kept; 1 below `maxPoints`. */
9
+ stride: number;
10
+ /** Mean distance between the kept points in world units: `voxelSize / cbrt(points per active voxel) * cbrt(stride)`. */
11
+ spacing: number;
12
+ /** World positions, `count * 3`. */
13
+ positions: Float32Array;
14
+ /** `Cd` per point (`count * 3`), or null when the grid has no 3-component real `Cd`. */
15
+ colors: Float32Array | null;
16
+ }
17
+ /** Options of {@link vdbPointRenderData}. */
18
+ export interface VDBPointRenderDataOptions {
19
+ /** Above this many points every `ceil(total / maxPoints)`-th point is kept (his default 4,000,000). */
20
+ maxPoints?: number;
21
+ /** Colour attribute name. Default `'Cd'`. */
22
+ color?: string;
23
+ }
24
+ /** His `defaultMaxPoints`. */
25
+ export declare const VDB_POINTS_DEFAULT_MAX = 4000000;
26
+ /**
27
+ * Builds the {@link VDBPointRenderData} of a parsed point data grid
28
+ * (`parseVdb(...).grids` entry with `valueType: 'ptdataidx32'`). Decodes the
29
+ * grid's points (`grid.points()`, cached by the grid).
30
+ */
31
+ export declare function vdbPointRenderData(grid: VdbPointDataGrid, options?: VDBPointRenderDataOptions): VDBPointRenderData;
@@ -0,0 +1,57 @@
1
+ /**
2
+ * The render-ready point list of a point data grid (K3.7): world positions,
3
+ * optional `Cd` colours, a subsample stride above `maxPoints`, and the mean
4
+ * point spacing that sizes the sprites. The input `VDBPoints` (`./three`)
5
+ * draws.
6
+ *
7
+ * Portions derived from mjurczyk/openvdb (MIT), commit 75e7345
8
+ * (`src/openvdb/utils/points.js` `createPointData`: the stride rule, the count,
9
+ * the spacing formula). Copyright (c) mjurczyk/openvdb contributors, MIT (see
10
+ * THIRD_PARTY_NOTICES.md). Changes: built on our parsed `VdbPointDataGrid.points()`
11
+ * (K4.2) in one pass instead of a sliced generator; `Cd` of any decoded
12
+ * 3-component real attribute (DIVERGES.md).
13
+ */
14
+ import { VDBToolsError } from "../errors.js";
15
+ /** His `defaultMaxPoints`. */
16
+ export const VDB_POINTS_DEFAULT_MAX = 4_000_000;
17
+ /**
18
+ * Builds the {@link VDBPointRenderData} of a parsed point data grid
19
+ * (`parseVdb(...).grids` entry with `valueType: 'ptdataidx32'`). Decodes the
20
+ * grid's points (`grid.points()`, cached by the grid).
21
+ */
22
+ export function vdbPointRenderData(grid, options = {}) {
23
+ if (grid?.valueType !== "ptdataidx32" || typeof grid.points !== "function") {
24
+ throw new VDBToolsError("VDB_UNSUPPORTED_GRID_TYPE", "vdbPointRenderData: grid must be a parsed point data grid (valueType 'ptdataidx32').");
25
+ }
26
+ const maxPoints = options.maxPoints ?? VDB_POINTS_DEFAULT_MAX;
27
+ if (!(maxPoints >= 1))
28
+ throw new VDBToolsError("VDB_BAD_OPTION", `vdbPointRenderData: maxPoints must be >= 1, got ${maxPoints}.`);
29
+ const list = grid.points();
30
+ const totalCount = list.count;
31
+ const stride = Math.max(1, Math.ceil(totalCount / maxPoints));
32
+ const count = totalCount > 0 ? Math.floor((totalCount - 1) / stride) + 1 : 0;
33
+ const positions = new Float32Array(count * 3);
34
+ const name = options.color ?? "Cd";
35
+ const cd = list.attributes[name];
36
+ const shape = list.attributeShapes[name];
37
+ const hasColors = cd !== undefined && shape?.components === 3 && shape.stride === 1 && (cd instanceof Float32Array || cd instanceof Float64Array);
38
+ const colors = hasColors ? new Float32Array(count * 3) : null;
39
+ for (let i = 0, j = 0; i < totalCount; i += stride, j++) {
40
+ positions[j * 3] = list.positions[i * 3];
41
+ positions[j * 3 + 1] = list.positions[i * 3 + 1];
42
+ positions[j * 3 + 2] = list.positions[i * 3 + 2];
43
+ if (colors) {
44
+ const c = cd;
45
+ colors[j * 3] = c[i * 3];
46
+ colors[j * 3 + 1] = c[i * 3 + 1];
47
+ colors[j * 3 + 2] = c[i * 3 + 2];
48
+ }
49
+ }
50
+ const [sx, sy, sz] = grid.transform.voxelSize;
51
+ const voxelSize = Math.cbrt(Math.abs(sx * sy * sz));
52
+ const activeVoxels = Number(grid.activeVoxelCount);
53
+ const pointsPerVoxel = activeVoxels > 0 ? totalCount / activeVoxels : 1;
54
+ const spacing = (voxelSize / Math.cbrt(pointsPerVoxel)) * Math.cbrt(stride);
55
+ return { count, totalCount, stride, spacing, positions, colors };
56
+ }
57
+ //# sourceMappingURL=point-render-data.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"point-render-data.js","sourceRoot":"","sources":["../../../src/tools/vdb/point-render-data.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AA2B7C,8BAA8B;AAC9B,MAAM,CAAC,MAAM,sBAAsB,GAAG,SAAS,CAAC;AAEhD;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAsB,EAAE,UA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C;IACpD,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IACnD,MAAM,cAAc,GAAG,YAAY,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IACxE,MAAM,OAAO,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC5E,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC;AACnE,CAAC","sourcesContent":["/**\n * The render-ready point list of a point data grid (K3.7): world positions,\n * optional `Cd` colours, a subsample stride above `maxPoints`, and the mean\n * point spacing that sizes the sprites. The input `VDBPoints` (`./three`)\n * draws.\n *\n * Portions derived from mjurczyk/openvdb (MIT), commit 75e7345\n * (`src/openvdb/utils/points.js` `createPointData`: the stride rule, the count,\n * the spacing formula). Copyright (c) mjurczyk/openvdb contributors, MIT (see\n * THIRD_PARTY_NOTICES.md). Changes: built on our parsed `VdbPointDataGrid.points()`\n * (K4.2) in one pass instead of a sliced generator; `Cd` of any decoded\n * 3-component real attribute (DIVERGES.md).\n */\nimport { VDBToolsError } from \"../errors.js\";\nimport type { VdbPointDataGrid } from \"./types.js\";\n\n/** What `VDBPoints` draws: world positions (xyz per point), optional linear RGB, the mean spacing. */\nexport interface VDBPointRenderData {\n /** Points in the arrays. */\n count: number;\n /** Points in the grid before the stride. */\n totalCount: number;\n /** Every `stride`-th point (in the grid's point order) is kept; 1 below `maxPoints`. */\n stride: number;\n /** Mean distance between the kept points in world units: `voxelSize / cbrt(points per active voxel) * cbrt(stride)`. */\n spacing: number;\n /** World positions, `count * 3`. */\n positions: Float32Array;\n /** `Cd` per point (`count * 3`), or null when the grid has no 3-component real `Cd`. */\n colors: Float32Array | null;\n}\n\n/** Options of {@link vdbPointRenderData}. */\nexport interface VDBPointRenderDataOptions {\n /** Above this many points every `ceil(total / maxPoints)`-th point is kept (his default 4,000,000). */\n maxPoints?: number;\n /** Colour attribute name. Default `'Cd'`. */\n color?: string;\n}\n\n/** His `defaultMaxPoints`. */\nexport const VDB_POINTS_DEFAULT_MAX = 4_000_000;\n\n/**\n * Builds the {@link VDBPointRenderData} of a parsed point data grid\n * (`parseVdb(...).grids` entry with `valueType: 'ptdataidx32'`). Decodes the\n * grid's points (`grid.points()`, cached by the grid).\n */\nexport function vdbPointRenderData(grid: VdbPointDataGrid, options: VDBPointRenderDataOptions = {}): VDBPointRenderData {\n if (grid?.valueType !== \"ptdataidx32\" || typeof grid.points !== \"function\") {\n throw new VDBToolsError(\"VDB_UNSUPPORTED_GRID_TYPE\", \"vdbPointRenderData: grid must be a parsed point data grid (valueType 'ptdataidx32').\");\n }\n const maxPoints = options.maxPoints ?? VDB_POINTS_DEFAULT_MAX;\n if (!(maxPoints >= 1)) throw new VDBToolsError(\"VDB_BAD_OPTION\", `vdbPointRenderData: maxPoints must be >= 1, got ${maxPoints}.`);\n const list = grid.points();\n const totalCount = list.count;\n const stride = Math.max(1, Math.ceil(totalCount / maxPoints));\n const count = totalCount > 0 ? Math.floor((totalCount - 1) / stride) + 1 : 0;\n const positions = new Float32Array(count * 3);\n const name = options.color ?? \"Cd\";\n const cd = list.attributes[name];\n const shape = list.attributeShapes[name];\n const hasColors = cd !== undefined && shape?.components === 3 && shape.stride === 1 && (cd instanceof Float32Array || cd instanceof Float64Array);\n const colors = hasColors ? new Float32Array(count * 3) : null;\n for (let i = 0, j = 0; i < totalCount; i += stride, j++) {\n positions[j * 3] = list.positions[i * 3]!;\n positions[j * 3 + 1] = list.positions[i * 3 + 1]!;\n positions[j * 3 + 2] = list.positions[i * 3 + 2]!;\n if (colors) {\n const c = cd as Float32Array | Float64Array;\n colors[j * 3] = c[i * 3]!;\n colors[j * 3 + 1] = c[i * 3 + 1]!;\n colors[j * 3 + 2] = c[i * 3 + 2]!;\n }\n }\n const [sx, sy, sz] = grid.transform.voxelSize;\n const voxelSize = Math.cbrt(Math.abs(sx * sy * sz));\n const activeVoxels = Number(grid.activeVoxelCount);\n const pointsPerVoxel = activeVoxels > 0 ? totalCount / activeVoxels : 1;\n const spacing = (voxelSize / Math.cbrt(pointsPerVoxel)) * Math.cbrt(stride);\n return { count, totalCount, stride, spacing, positions, colors };\n}\n"]}
@@ -0,0 +1,160 @@
1
+ /**
2
+ * points.ts — OpenVDB point data grids (`points::PointDataGrid`, grid type
3
+ * `Tree_ptdataidx32_5_4_3`): the multi-pass leaf buffers and the attribute
4
+ * arrays they hold.
5
+ *
6
+ * Portions derived from mjurczyk/openvdb (MIT), commit 75e7345
7
+ * (`src/openvdb/core/PointDataBuffers.js`, `src/openvdb/utils/points.js`): the
8
+ * pass walk and the position decode follow the same OpenVDB sources his reader
9
+ * cites. The format authority is OpenVDB itself (pinned a532de55):
10
+ * `Grid::readBuffers` (multi-pass I/O), `points/PointDataGrid.h`
11
+ * (`PointDataLeafNode::readBuffers`, the `PointDataIndex32`
12
+ * `readCompressedValues` specialization), `points/AttributeSet.cc`
13
+ * (`Descriptor::read`, `readMetadata`, `groupIndex`), `points/AttributeArray.h`
14
+ * (`TypedAttributeArray::readMetadata` / `readBuffers` / `readPagedBuffers`,
15
+ * the codecs) and `points/StreamCompression.cc` (`PagedInputStream`, `Page`).
16
+ *
17
+ * ## On-disk layout
18
+ *
19
+ * The tree topology is ordinary (leaves store only their value mask there).
20
+ * The buffers start with a `u16 numPasses`; then the whole tree is walked
21
+ * `numPasses` times, every leaf reading the part of its data that belongs to
22
+ * the pass. With `n = (numPasses - 4) / 2` attributes:
23
+ *
24
+ * pass 0 u16 compressed size of the leaf's voxel buffer
25
+ * pass 1 [u8 header, attribute descriptor, (header & 2) u64 skip]
26
+ * unless a previous leaf shared its descriptor (header & 1);
27
+ * then each attribute array's metadata
28
+ * pass 2..n+1 attribute (pass - 2): page headers of paged arrays
29
+ * pass n+2 the voxel buffer: value mask, then u16 size and a Blosc
30
+ * frame (or 0xFFFF and 512 raw u32 end offsets)
31
+ * pass n+3..2n+2 attribute (pass - n - 3): page bodies of paged arrays, or
32
+ * the whole buffer of a non-paged array
33
+ * pass 2n+3 cleanup (no I/O)
34
+ *
35
+ * Paged arrays (Blosc files) share pages: a page holds the arrays of many
36
+ * consecutive leaves. A page header is an i32 compressed size and, when
37
+ * positive, an i32 uncompressed size; a negative size means the page is
38
+ * stored raw. Page bodies are read only when the next array starts a new
39
+ * page, so the bytes stay views into the file until {@link decodePoints}.
40
+ *
41
+ * Each leaf voxel holds the *end* offset of its points in the leaf's arrays.
42
+ * The position attribute `P` is a voxel-space offset from the voxel centre;
43
+ * world position = `indexToWorld(ijk + P)`.
44
+ *
45
+ * ## Hostile input (K4.2 hardening)
46
+ *
47
+ * Every count, size and offset read from the file is bounded before it drives
48
+ * an allocation or a loop, and every failure is a `VdbFormatError` or
49
+ * `VDBUnsupportedError`:
50
+ *
51
+ * - The pass loops only visit the leaves that own an array for the pass, so
52
+ * their work is bounded by the array metadata actually stored (a large
53
+ * `numPasses` costs nothing). A leaf with more attributes than the passes
54
+ * cover is rejected.
55
+ * - Page headers: a page body must fit in the file, and a Blosc page may claim
56
+ * at most {@link MAX_BLOSC_RATIO} times its compressed size. A page must be
57
+ * filled exactly by the arrays assigned to it.
58
+ * - Point counts: the grid's total point count, times the 12 bytes of its
59
+ * positions, may not exceed {@link MAX_POINT_EXPANSION} times the file size.
60
+ * Uniform arrays store one value for any number of points, so nothing else
61
+ * bounds a count.
62
+ * - Decoding: every output array and every decoded page is charged against a
63
+ * budget of {@link MAX_POINT_EXPANSION} times the file size before it is
64
+ * allocated. Strides and group offsets are range-checked (no int32
65
+ * wrap-around).
66
+ */
67
+ import type { ByteReader } from "./byte-reader.js";
68
+ import type { VdbPointAttributeInfo, VdbPointList } from "./types.js";
69
+ /**
70
+ * The most a Blosc1 frame from OpenVDB can expand: deflate's worst case is
71
+ * about 1032:1 and LZ4's 255:1 (each length byte adds at most 255 output
72
+ * bytes). A Blosc page header claiming more is not a real page.
73
+ */
74
+ export declare const MAX_BLOSC_RATIO = 1032;
75
+ /**
76
+ * Decoded point output allowed per byte of the source file. The real samples
77
+ * need under 3 (waterfall_points: 156 MB in, 381 MB of positions and
78
+ * attributes out); 256 matches LZ4's ceiling and leaves room for uniform
79
+ * arrays, which store one value for a whole leaf.
80
+ */
81
+ export declare const MAX_POINT_EXPANSION = 256;
82
+ /** One attribute set descriptor (`AttributeSet::Descriptor`). */
83
+ export interface PointDescriptor {
84
+ /** In attribute-set order (`index` = position). */
85
+ attributes: VdbPointAttributeInfo[];
86
+ /** Group name -> bit offset across the group attributes. */
87
+ groups: {
88
+ name: string;
89
+ offset: number;
90
+ }[];
91
+ }
92
+ /** A page of a paged attribute stream (`compression::Page`). */
93
+ export interface PointPage {
94
+ /** > 0: Blosc frame size; < 0: raw, `-compressedBytes` bytes. */
95
+ compressedBytes: number;
96
+ uncompressedBytes: number;
97
+ /** The page body as stored (a view into the file), once read. */
98
+ data: Uint8Array | null;
99
+ }
100
+ /** One leaf's attribute array (`TypedAttributeArray` metadata plus where its bytes are). */
101
+ export interface PointArrayData {
102
+ flags: number;
103
+ serialization: number;
104
+ /** Points in the array (`mSize`). */
105
+ size: number;
106
+ /** Stride (constant-stride arrays) or total element count. */
107
+ strideOrTotal: number;
108
+ /** Uncompressed array bytes for paged arrays; stored bytes for non-paged ones. */
109
+ bytes: number;
110
+ isUniform: boolean;
111
+ isPaged: boolean;
112
+ /** Non-paged arrays: the stored bytes and whether they are a Blosc frame. */
113
+ raw: Uint8Array | null;
114
+ bloscCompressed: boolean;
115
+ /** Paged arrays: the page and the array's byte offset inside it. */
116
+ page: PointPage | null;
117
+ pageOffset: number;
118
+ }
119
+ /** One point data leaf after the buffer passes. */
120
+ export interface PointLeafData {
121
+ origin: [number, number, number];
122
+ valueMask: Uint32Array;
123
+ /** Per-voxel end offsets into the leaf's arrays. */
124
+ offsets: Uint32Array;
125
+ descriptor: PointDescriptor;
126
+ arrays: PointArrayData[];
127
+ }
128
+ export interface ReadPointBuffersOptions {
129
+ fileVersion: number;
130
+ /** Leaves in buffer order, with their topology origins. */
131
+ leaves: readonly {
132
+ origin: [number, number, number];
133
+ }[];
134
+ }
135
+ /**
136
+ * Reads a point data grid's buffers (after its topology): `u16 numPasses`,
137
+ * then every pass over every leaf. Returns one entry per leaf, in order.
138
+ */
139
+ export declare function readPointDataBuffers(reader: ByteReader, opts: ReadPointBuffersOptions): PointLeafData[];
140
+ /**
141
+ * `math::QuantizedUnitVec::sNormalizationWeights`, generated: `1 / |(x, y, 126 - x - y)|`
142
+ * per slot. Exported for the test against OpenVDB's literal table.
143
+ */
144
+ export declare function unitVecWeightTable(): Float32Array;
145
+ /** `math::QuantizedUnitVec::unpack`. */
146
+ export declare function unpackUnitVec(data: number, out: Float32Array | Float64Array, at: number): void;
147
+ export interface DecodePointsOptions {
148
+ /**
149
+ * Upper bound on the bytes the decode may allocate (outputs plus decoded
150
+ * pages). The parser passes {@link MAX_POINT_EXPANSION} times the file size.
151
+ * Default: unlimited.
152
+ */
153
+ maxOutputBytes?: number;
154
+ }
155
+ /**
156
+ * Decodes the points of a parsed point data grid: world-space positions from
157
+ * `P` (through `matrix`, a row-major 4x4 index->world transform) and every
158
+ * other attribute the codec table covers.
159
+ */
160
+ export declare function decodePoints(leaves: readonly PointLeafData[], matrix: readonly number[], options?: DecodePointsOptions): VdbPointList;