@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,835 @@
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
+ * ## OpenVDB v14.0.0 security checks (K7.C)
68
+ *
69
+ * OpenVDB v14 throws `IoError` on four PointDataGrid inconsistencies
70
+ * (CHANGES "Security Fixes"; `TypedAttributeArray::readMetadata` /
71
+ * `readBuffers` / `readPagedBuffers`, `PagedInputStream::createHandle` /
72
+ * `read`, `Page::readHeader`, `codecs/PointDataCodec.h`
73
+ * `validateReadOffsets` / `validatePointDataAttributeCount`). Each maps here:
74
+ *
75
+ * 1. Attribute byte count smaller than the array: a byte count below its 6
76
+ * header bytes, a size of 0, a constant stride of 0 or with `size * stride`
77
+ * past u32, and a total size below `size` fail in `readArrayMetadata`;
78
+ * the stored bytes must equal the array's exactly (stricter than v14's
79
+ * "at least") when {@link decodePoints} reads them.
80
+ * 2. Page size that does not match its data: page headers of 0, i32 minimum or
81
+ * a non-positive uncompressed size, an array of 0 bytes or past its page
82
+ * (`createPageHandle`), and a page whose arrays don't fill it exactly
83
+ * (`checkStreamComplete`, stricter than v14's unread-page check); a
84
+ * decoded page must be exactly its header's size.
85
+ * 3. Voxel offsets beyond the arrays: end offsets must not decrease, and every
86
+ * array's size must equal the leaf's last offset (v14: offsets at most the
87
+ * last, the last at most each size; ours is exact).
88
+ * 4. Pass count too small: a leaf with more arrays than `(numPasses - 4) / 2`
89
+ * covers fails (and fewer than 4 passes with leaves).
90
+ */
91
+ import { decompressBlosc } from "./blosc.js";
92
+ import { VdbFormatError, VDBUnsupportedError } from "./errors.js";
93
+ import { halfToFloat } from "./half-float.js";
94
+ import { readMetadataMap } from "./metadata.js";
95
+ const LEAF_NUM_VALUES = 512;
96
+ const LEAF_LOG2DIM = 3;
97
+ /** `PointDataLeafNode::readBuffers` descriptor header bits. */
98
+ const HEADER_SHARED_DESCRIPTOR = 0x1;
99
+ const HEADER_SKIP_BYTES = 0x2;
100
+ /** `AttributeArray::SerializationFlag`. */
101
+ const WRITE_STRIDED = 0x1;
102
+ const WRITE_UNIFORM = 0x2;
103
+ const WRITE_PAGED = 0x8;
104
+ /** `AttributeArray::Flag::CONSTANTSTRIDE`. */
105
+ const FLAG_CONSTANT_STRIDE = 0x8;
106
+ /** The `u16` voxel-buffer size that marks an uncompressed buffer. */
107
+ const VOXEL_BUFFER_UNCOMPRESSED = 0xffff;
108
+ /**
109
+ * The most a Blosc1 frame from OpenVDB can expand: deflate's worst case is
110
+ * about 1032:1 and LZ4's 255:1 (each length byte adds at most 255 output
111
+ * bytes). A Blosc page header claiming more is not a real page.
112
+ */
113
+ export const MAX_BLOSC_RATIO = 1032;
114
+ /**
115
+ * Decoded point output allowed per byte of the source file. The real samples
116
+ * need under 3 (waterfall_points: 156 MB in, 381 MB of positions and
117
+ * attributes out); 256 matches LZ4's ceiling and leaves room for uniform
118
+ * arrays, which store one value for a whole leaf.
119
+ */
120
+ export const MAX_POINT_EXPANSION = 256;
121
+ /** Bytes of decoded position per point (3 x f32). */
122
+ const POSITION_BYTES = 12;
123
+ /** Descriptor limits: far above any real file, low enough to bound the loops. */
124
+ const MAX_ATTRIBUTES = 1 << 16;
125
+ const MAX_GROUPS = 1 << 16;
126
+ /** `AttributeSet::Descriptor::read`. */
127
+ function readDescriptor(reader) {
128
+ const count = reader.u64();
129
+ if (count > BigInt(MAX_ATTRIBUTES))
130
+ throw new VdbFormatError(`point attribute descriptor claims ${count} attributes`);
131
+ const n = Number(count);
132
+ const types = [];
133
+ for (let i = 0; i < n; i++)
134
+ types.push({ type: reader.string(), codec: reader.string() });
135
+ const names = new Array(n);
136
+ const seen = new Set();
137
+ for (let i = 0; i < n; i++) {
138
+ const name = reader.string();
139
+ const index = reader.u64();
140
+ if (index >= count)
141
+ throw new VdbFormatError(`point attribute "${name}" has index ${index} of ${n}`);
142
+ // Descriptor::read inserts into a std::map, so a repeated name would leave an attribute unnamed.
143
+ if (seen.has(name))
144
+ throw new VdbFormatError(`point attribute name "${name}" appears twice`);
145
+ seen.add(name);
146
+ names[Number(index)] = name;
147
+ }
148
+ const attributes = types.map(({ type, codec }, index) => {
149
+ const name = names[index];
150
+ if (name === undefined)
151
+ throw new VdbFormatError(`point attribute ${index} has no name`);
152
+ return { name, type, codec, index };
153
+ });
154
+ const groupCount = reader.u64();
155
+ if (groupCount > BigInt(MAX_GROUPS))
156
+ throw new VdbFormatError(`point attribute descriptor claims ${groupCount} groups`);
157
+ const groups = [];
158
+ const groupNames = new Set();
159
+ for (let i = 0; i < Number(groupCount); i++) {
160
+ const name = reader.string();
161
+ const offset = reader.u64();
162
+ // The group map is a std::map too: the first entry for a name wins.
163
+ if (groupNames.has(name))
164
+ continue;
165
+ groupNames.add(name);
166
+ // Range-checked against the group arrays when decoded (`Descriptor::groupIndex`);
167
+ // anything past 2^32 bits is out of range for any descriptor.
168
+ groups.push({ name, offset: offset > 0xffffffffn ? Number.MAX_SAFE_INTEGER : Number(offset) });
169
+ }
170
+ readMetadataMap(reader); // descriptor metadata (default values, string tables): not needed here
171
+ return { attributes, groups };
172
+ }
173
+ /** `TypedAttributeArray::readMetadata`. */
174
+ function readArrayMetadata(reader) {
175
+ const total = reader.u64();
176
+ const flags = reader.u8();
177
+ const serialization = reader.u8();
178
+ const size = reader.u32();
179
+ if (serialization >= 0x10) {
180
+ throw new VDBUnsupportedError(`point attribute serialization flags 0x${serialization.toString(16)}`);
181
+ }
182
+ if (total < 6n || total > BigInt(Number.MAX_SAFE_INTEGER)) {
183
+ throw new VdbFormatError(`point attribute array byte count ${total} is out of range`);
184
+ }
185
+ const bytes = Number(total) - 2 - 4; // minus the two flag bytes and the u32 size
186
+ const strideOrTotal = serialization & WRITE_STRIDED ? reader.u32() : 1;
187
+ // OpenVDB v14 (`readMetadata`): size and stride come from the file, so a size of 0, a constant
188
+ // stride of 0 or whose `size * stride` passes u32, or a total below the size is an IoError.
189
+ if (size === 0)
190
+ throw new VdbFormatError("point attribute array has a size of 0");
191
+ const constantStride = !(serialization & WRITE_STRIDED) || (flags & FLAG_CONSTANT_STRIDE) !== 0;
192
+ if (constantStride) {
193
+ if (strideOrTotal === 0)
194
+ throw new VdbFormatError("point attribute array has a constant stride of 0");
195
+ if (size * strideOrTotal > 0xffffffff) {
196
+ throw new VdbFormatError(`point attribute array of ${size} x stride ${strideOrTotal} values passes 2^32`);
197
+ }
198
+ }
199
+ else if (strideOrTotal < size) {
200
+ throw new VdbFormatError(`point attribute array has a total size of ${strideOrTotal}, below its ${size} points`);
201
+ }
202
+ return {
203
+ flags,
204
+ serialization,
205
+ size,
206
+ strideOrTotal,
207
+ bytes,
208
+ isUniform: (serialization & WRITE_UNIFORM) !== 0,
209
+ isPaged: (serialization & WRITE_PAGED) !== 0,
210
+ raw: null,
211
+ bloscCompressed: false,
212
+ page: null,
213
+ pageOffset: 0,
214
+ };
215
+ }
216
+ /** `PagedInputStream::createHandle`: assign the array its page, reading a page header when one starts. */
217
+ function createPageHandle(reader, stream, array) {
218
+ if (stream.byteIndex === stream.uncompressedBytes) {
219
+ const compressedBytes = reader.i32();
220
+ const uncompressedBytes = compressedBytes > 0 ? reader.i32() : -compressedBytes;
221
+ // OpenVDB v14 `Page::readHeader`: 0 and the i32 minimum (whose negation overflows) are invalid.
222
+ if (compressedBytes === 0 || compressedBytes === -0x80000000 || uncompressedBytes <= 0) {
223
+ throw new VdbFormatError(`point attribute page header ${compressedBytes}/${uncompressedBytes} is empty`);
224
+ }
225
+ // The body follows later in the file, so it can be no larger than the file.
226
+ const storedBytes = Math.abs(compressedBytes);
227
+ if (storedBytes > reader.length) {
228
+ throw new VdbFormatError(`point attribute page header claims ${storedBytes} stored bytes in a ${reader.length}-byte file`);
229
+ }
230
+ if (compressedBytes > 0 && uncompressedBytes > Math.max(compressedBytes * MAX_BLOSC_RATIO, BLOSC_PAD_BYTES)) {
231
+ throw new VdbFormatError(`point attribute page header claims ${uncompressedBytes} bytes from a ${compressedBytes}-byte Blosc frame`);
232
+ }
233
+ stream.page = { compressedBytes, uncompressedBytes, data: null };
234
+ stream.uncompressedBytes = uncompressedBytes;
235
+ stream.byteIndex = 0;
236
+ }
237
+ // OpenVDB v14 `PagedInputStream::createHandle`: a handle of n <= 0 bytes, or past the page, is an IoError.
238
+ if (array.bytes <= 0 || stream.byteIndex + array.bytes > stream.uncompressedBytes) {
239
+ throw new VdbFormatError(`point attribute array of ${array.bytes} bytes ${array.bytes <= 0 ? "is empty in" : "overruns"} its ${stream.uncompressedBytes}-byte page`);
240
+ }
241
+ array.page = stream.page;
242
+ array.pageOffset = stream.byteIndex;
243
+ stream.byteIndex += array.bytes;
244
+ }
245
+ /** `PagedInputStream::read`: read the array's page body when it starts a new page. */
246
+ function readPage(reader, stream, array) {
247
+ const page = array.page;
248
+ if (!page)
249
+ throw new VdbFormatError("paged point attribute array has no page");
250
+ if (stream.byteIndex === stream.uncompressedBytes) {
251
+ stream.uncompressedBytes = page.uncompressedBytes;
252
+ page.data = reader.bytes_(Math.abs(page.compressedBytes));
253
+ stream.byteIndex = 0;
254
+ }
255
+ stream.byteIndex += array.bytes;
256
+ }
257
+ /** `LeafNode::readBuffers` with the `PointDataIndex32` `readCompressedValues` specialization. */
258
+ function readVoxelBuffer(reader, fileVersion) {
259
+ const valueMask = reader.maskWords(LEAF_NUM_VALUES);
260
+ if (fileVersion < 222) {
261
+ reader.vec3i(); // origin
262
+ const numBuffers = reader.u8();
263
+ if (numBuffers !== 1)
264
+ throw new VdbFormatError(`point leaf numBuffers ${numBuffers} !== 1`);
265
+ }
266
+ const destBytes = LEAF_NUM_VALUES * 4;
267
+ const size = reader.u16();
268
+ const bytes = size === VOXEL_BUFFER_UNCOMPRESSED
269
+ ? reader.bytes_(destBytes)
270
+ : decompressBlosc(reader.bytes_(size), { maxBytes: destBytes, expectedCbytes: size });
271
+ if (bytes.length !== destBytes) {
272
+ throw new VdbFormatError(`point leaf voxel buffer decoded to ${bytes.length} bytes, expected ${destBytes}`);
273
+ }
274
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
275
+ const offsets = new Uint32Array(LEAF_NUM_VALUES);
276
+ for (let i = 0; i < LEAF_NUM_VALUES; i++)
277
+ offsets[i] = view.getUint32(i * 4, true);
278
+ for (let i = 1; i < LEAF_NUM_VALUES; i++) {
279
+ if (offsets[i] < offsets[i - 1])
280
+ throw new VdbFormatError("point leaf end offsets decrease");
281
+ }
282
+ return { valueMask, offsets };
283
+ }
284
+ /**
285
+ * Reads a point data grid's buffers (after its topology): `u16 numPasses`,
286
+ * then every pass over every leaf. Returns one entry per leaf, in order.
287
+ */
288
+ export function readPointDataBuffers(reader, opts) {
289
+ const numPasses = reader.u16();
290
+ const n = opts.leaves.length;
291
+ if (n === 0)
292
+ return [];
293
+ if (numPasses < 4)
294
+ throw new VdbFormatError(`point data grid has ${numPasses} buffer passes (expected >= 4)`);
295
+ const attributeCount = Math.floor((numPasses - 4) / 2);
296
+ const leaves = opts.leaves.map((l) => ({
297
+ origin: l.origin,
298
+ valueMask: EMPTY_MASK,
299
+ offsets: EMPTY_OFFSETS,
300
+ descriptor: { attributes: [], groups: [] },
301
+ arrays: [],
302
+ }));
303
+ let sharedDescriptor = null;
304
+ // Pass 0: voxel buffer sizes (only used by OpenVDB for delayed loading).
305
+ for (let i = 0; i < n; i++)
306
+ reader.u16();
307
+ // Pass 1: descriptors and attribute array metadata.
308
+ let maxArrays = 0;
309
+ for (const leaf of leaves) {
310
+ if (sharedDescriptor) {
311
+ leaf.descriptor = sharedDescriptor;
312
+ }
313
+ else {
314
+ const header = reader.u8();
315
+ leaf.descriptor = readDescriptor(reader);
316
+ if (header & HEADER_SHARED_DESCRIPTOR)
317
+ sharedDescriptor = leaf.descriptor;
318
+ if (header & HEADER_SKIP_BYTES) {
319
+ const skip = reader.u64();
320
+ if (skip > BigInt(reader.length - reader.pos)) {
321
+ throw new VdbFormatError(`point leaf descriptor asks to skip ${skip} bytes past the end of the file`);
322
+ }
323
+ reader.skip(Number(skip));
324
+ }
325
+ if (header > 3)
326
+ throw new VDBUnsupportedError(`point leaf descriptor header flags 0x${header.toString(16)}`);
327
+ }
328
+ leaf.arrays = leaf.descriptor.attributes.map(() => readArrayMetadata(reader));
329
+ maxArrays = Math.max(maxArrays, leaf.arrays.length);
330
+ }
331
+ // `PointDataLeafNode::buffers()` is 2 * attributes + 4, and the grid writes the
332
+ // largest leaf's count: arrays past `attributeCount` would never be read.
333
+ if (maxArrays > attributeCount) {
334
+ throw new VdbFormatError(`point leaf has ${maxArrays} attribute arrays, but the grid writes ${numPasses} passes (room for ${attributeCount})`);
335
+ }
336
+ // The leaves that own array i, so passes cost no more than the arrays stored.
337
+ const owners = Array.from({ length: maxArrays }, () => []);
338
+ for (const leaf of leaves)
339
+ for (let i = 0; i < leaf.arrays.length; i++)
340
+ owners[i].push(leaf);
341
+ const streams = Array.from({ length: maxArrays }, () => ({
342
+ page: null,
343
+ byteIndex: 0,
344
+ uncompressedBytes: 0,
345
+ }));
346
+ // Passes 2 .. n+1: page headers.
347
+ for (let i = 0; i < maxArrays; i++) {
348
+ for (const leaf of owners[i]) {
349
+ const array = leaf.arrays[i];
350
+ if (array.isPaged)
351
+ createPageHandle(reader, streams[i], array);
352
+ }
353
+ checkStreamComplete(streams[i], i, "page headers");
354
+ }
355
+ // Pass n+2: voxel buffers. Every attribute array holds one entry per point of the leaf.
356
+ let totalPoints = 0;
357
+ for (const leaf of leaves) {
358
+ const { valueMask, offsets } = readVoxelBuffer(reader, opts.fileVersion);
359
+ leaf.valueMask = valueMask;
360
+ leaf.offsets = offsets;
361
+ const points = offsets[LEAF_NUM_VALUES - 1];
362
+ const bad = leaf.arrays.find((a) => a.size !== points);
363
+ if (bad) {
364
+ throw new VdbFormatError(`point leaf has ${points} points but an attribute array of size ${bad.size}`);
365
+ }
366
+ totalPoints += points;
367
+ }
368
+ if (totalPoints * POSITION_BYTES > MAX_POINT_EXPANSION * reader.length) {
369
+ throw new VdbFormatError(`point data grid claims ${totalPoints} points, more than a ${reader.length}-byte file can hold`);
370
+ }
371
+ // Passes n+3 .. 2n+2: page bodies, or the buffers of non-paged arrays.
372
+ for (let i = 0; i < maxArrays; i++) {
373
+ for (const leaf of owners[i]) {
374
+ const array = leaf.arrays[i];
375
+ if (array.isPaged) {
376
+ readPage(reader, streams[i], array);
377
+ }
378
+ else {
379
+ // TypedAttributeArray::readBuffers.
380
+ array.bloscCompressed = array.isUniform ? false : reader.u8() === 1;
381
+ array.raw = reader.bytes_(array.bytes);
382
+ }
383
+ }
384
+ checkStreamComplete(streams[i], i, "page bodies");
385
+ }
386
+ // Passes past 2n+2 are cleanup only (no I/O), however many the header claims.
387
+ return leaves;
388
+ }
389
+ const EMPTY_MASK = new Uint32Array(LEAF_NUM_VALUES / 32);
390
+ const EMPTY_OFFSETS = new Uint32Array(LEAF_NUM_VALUES);
391
+ /** A paged stream must end on a page boundary, or the next pass reads out of step. */
392
+ function checkStreamComplete(stream, index, what) {
393
+ if (stream.byteIndex !== stream.uncompressedBytes) {
394
+ throw new VdbFormatError(`point attribute ${index} ${what} end mid-page (${stream.byteIndex} of ${stream.uncompressedBytes} bytes)`);
395
+ }
396
+ }
397
+ /** OpenVDB `typeNameAsString` -> element shape. */
398
+ const VALUE_TYPES = {
399
+ bool: { components: 1, kind: "bool" },
400
+ half: { components: 1, kind: "f16" },
401
+ float: { components: 1, kind: "f32" },
402
+ double: { components: 1, kind: "f64" },
403
+ int8: { components: 1, kind: "i8" },
404
+ uint8: { components: 1, kind: "u8" },
405
+ int16: { components: 1, kind: "i16" },
406
+ uint16: { components: 1, kind: "u16" },
407
+ int32: { components: 1, kind: "i32" },
408
+ uint32: { components: 1, kind: "u32" },
409
+ int64: { components: 1, kind: "i64" },
410
+ uint64: { components: 1, kind: "u64" },
411
+ vec2i: { components: 2, kind: "i32" },
412
+ vec2s: { components: 2, kind: "f32" },
413
+ vec2d: { components: 2, kind: "f64" },
414
+ vec3u8: { components: 3, kind: "u8" },
415
+ vec3u16: { components: 3, kind: "u16" },
416
+ vec3i: { components: 3, kind: "i32" },
417
+ vec3s: { components: 3, kind: "f32" },
418
+ vec3d: { components: 3, kind: "f64" },
419
+ vec4i: { components: 4, kind: "i32" },
420
+ vec4s: { components: 4, kind: "f32" },
421
+ vec4d: { components: 4, kind: "f64" },
422
+ quats: { components: 4, kind: "f32" },
423
+ quatd: { components: 4, kind: "f64" },
424
+ mat3s: { components: 9, kind: "f32" },
425
+ mat3d: { components: 9, kind: "f64" },
426
+ mat4s: { components: 16, kind: "f32" },
427
+ mat4d: { components: 16, kind: "f64" },
428
+ };
429
+ const KIND_BYTES = {
430
+ bool: 1,
431
+ i8: 1,
432
+ u8: 1,
433
+ i16: 2,
434
+ u16: 2,
435
+ i32: 4,
436
+ u32: 4,
437
+ i64: 8,
438
+ u64: 8,
439
+ f16: 2,
440
+ f32: 4,
441
+ f64: 8,
442
+ };
443
+ const OUTPUT_CTOR = {
444
+ bool: Uint8Array,
445
+ i8: Int8Array,
446
+ u8: Uint8Array,
447
+ i16: Int16Array,
448
+ u16: Uint16Array,
449
+ i32: Int32Array,
450
+ u32: Uint32Array,
451
+ i64: BigInt64Array,
452
+ u64: BigUint64Array,
453
+ f16: Float32Array,
454
+ f32: Float32Array,
455
+ f64: Float64Array,
456
+ };
457
+ function scalarReader(kind) {
458
+ switch (kind) {
459
+ case "bool":
460
+ case "u8":
461
+ return (v, at) => v.getUint8(at);
462
+ case "i8":
463
+ return (v, at) => v.getInt8(at);
464
+ case "i16":
465
+ return (v, at) => v.getInt16(at, true);
466
+ case "u16":
467
+ return (v, at) => v.getUint16(at, true);
468
+ case "i32":
469
+ return (v, at) => v.getInt32(at, true);
470
+ case "u32":
471
+ return (v, at) => v.getUint32(at, true);
472
+ case "i64":
473
+ return (v, at) => v.getBigInt64(at, true);
474
+ case "u64":
475
+ return (v, at) => v.getBigUint64(at, true);
476
+ case "f16":
477
+ return (v, at) => halfToFloat(v.getUint16(at, true));
478
+ case "f32":
479
+ return (v, at) => v.getFloat32(at, true);
480
+ case "f64":
481
+ return (v, at) => v.getFloat64(at, true);
482
+ }
483
+ }
484
+ const fround = Math.fround;
485
+ let unitVecWeights = null;
486
+ /**
487
+ * `math::QuantizedUnitVec::sNormalizationWeights`, generated: `1 / |(x, y, 126 - x - y)|`
488
+ * per slot. Exported for the test against OpenVDB's literal table.
489
+ */
490
+ export function unitVecWeightTable() {
491
+ if (unitVecWeights)
492
+ return unitVecWeights;
493
+ const table = new Float32Array(8192);
494
+ for (let slot = 0; slot < 8192; slot++) {
495
+ let x = (slot & 0x1f80) >> 7;
496
+ let y = slot & 0x007f;
497
+ if (x + y > 126) {
498
+ x = 127 - x;
499
+ y = 127 - y;
500
+ }
501
+ const z = 126 - x - y;
502
+ table[slot] = 1 / Math.sqrt(x * x + y * y + z * z);
503
+ }
504
+ unitVecWeights = table;
505
+ return table;
506
+ }
507
+ /** `math::QuantizedUnitVec::unpack`. */
508
+ export function unpackUnitVec(data, out, at) {
509
+ const w = unitVecWeightTable()[data & 0x1fff];
510
+ let x = (data & 0x1f80) >> 7;
511
+ let y = data & 0x007f;
512
+ if (x + y > 126) {
513
+ x = 127 - x;
514
+ y = 127 - y;
515
+ }
516
+ let vx = fround(x * w);
517
+ let vy = fround(y * w);
518
+ let vz = fround((126 - x - y) * w);
519
+ if (data & 0x8000)
520
+ vx = -vx;
521
+ if (data & 0x4000)
522
+ vy = -vy;
523
+ if (data & 0x2000)
524
+ vz = -vz;
525
+ out[at] = vx;
526
+ out[at + 1] = vy;
527
+ out[at + 2] = vz;
528
+ }
529
+ /** The codec for an attribute's (type, codec) pair, or null when unsupported. */
530
+ function attributeCodec(type, codec) {
531
+ const shape = VALUE_TYPES[type];
532
+ if (!shape)
533
+ return null;
534
+ const { components, kind } = shape;
535
+ const perComponent = (storage, map, output) => {
536
+ const read = scalarReader(storage);
537
+ const step = KIND_BYTES[storage];
538
+ return {
539
+ components,
540
+ storageBytes: step * components,
541
+ output,
542
+ decode(view, at, out, outAt) {
543
+ for (let c = 0; c < components; c++)
544
+ out[outAt + c] = map(read(view, at + c * step));
545
+ },
546
+ };
547
+ };
548
+ switch (codec) {
549
+ case "null":
550
+ case "str": {
551
+ const read = scalarReader(kind);
552
+ const step = KIND_BYTES[kind];
553
+ return {
554
+ components,
555
+ storageBytes: step * components,
556
+ output: OUTPUT_CTOR[kind],
557
+ decode(view, at, out, outAt) {
558
+ for (let c = 0; c < components; c++)
559
+ out[outAt + c] = read(view, at + c * step);
560
+ },
561
+ };
562
+ }
563
+ case "trnc":
564
+ // TruncateTrait: float -> half, int -> short (and their Vec3s).
565
+ if (kind === "f32")
566
+ return perComponent("f16", (x) => x, Float32Array);
567
+ if (kind === "i32")
568
+ return perComponent("i16", (x) => x, Int32Array);
569
+ return null;
570
+ case "fxpt8":
571
+ case "fxpt16":
572
+ case "ufxpt8":
573
+ case "ufxpt16": {
574
+ if (kind !== "f32")
575
+ return null;
576
+ const oneByte = codec.endsWith("8");
577
+ const max = oneByte ? 255 : 65535;
578
+ // FixedPointCodec: float(s) / float(max), then PositionRange shifts by -0.5.
579
+ const shift = codec.startsWith("u") ? 0 : 0.5;
580
+ return perComponent(oneByte ? "u8" : "u16", (s) => fround(fround(s / max) - shift), Float32Array);
581
+ }
582
+ case "uvec":
583
+ if (type !== "vec3s")
584
+ return null;
585
+ return {
586
+ components: 3,
587
+ storageBytes: 2,
588
+ output: Float32Array,
589
+ decode(view, at, out, outAt) {
590
+ unpackUnitVec(view.getUint16(at, true), out, outAt);
591
+ },
592
+ };
593
+ default:
594
+ return null;
595
+ }
596
+ }
597
+ /** Element stride of an array, or null for a variable-stride array. */
598
+ function arrayStride(array) {
599
+ if (!(array.serialization & WRITE_STRIDED))
600
+ return 1;
601
+ return array.flags & FLAG_CONSTANT_STRIDE ? array.strideOrTotal : null;
602
+ }
603
+ /** OpenVDB pads Blosc input shorter than this with zeros (`BLOSC_PAD_BYTES`). */
604
+ const BLOSC_PAD_BYTES = 48;
605
+ /**
606
+ * Decompresses a Blosc frame that must hold `expectedBytes` bytes, accepting
607
+ * the zero-padded 48-byte frame OpenVDB writes for shorter input (the rule in
608
+ * `compression::bloscDecompress`).
609
+ */
610
+ function decompressExact(frame, expectedBytes, what) {
611
+ const bytes = decompressBlosc(frame, {
612
+ maxBytes: Math.max(expectedBytes, BLOSC_PAD_BYTES),
613
+ expectedCbytes: frame.length,
614
+ });
615
+ const padded = bytes.length === BLOSC_PAD_BYTES && expectedBytes <= BLOSC_PAD_BYTES;
616
+ if (bytes.length !== expectedBytes && !padded) {
617
+ throw new VdbFormatError(`${what} decoded to ${bytes.length} bytes, expected ${expectedBytes}`);
618
+ }
619
+ return bytes;
620
+ }
621
+ /**
622
+ * The decoded-output budget of one {@link decodePoints} call. Output arrays
623
+ * and decoded pages are charged before they are allocated; a short-lived
624
+ * buffer is only checked against what is left.
625
+ */
626
+ class DecodeBudget {
627
+ limit;
628
+ used = 0;
629
+ constructor(limit) {
630
+ this.limit = limit;
631
+ }
632
+ fail(bytes, what) {
633
+ throw new VdbFormatError(`decoding ${what} needs ${bytes} bytes, past the point grid's ${this.limit}-byte output budget ` +
634
+ `(${MAX_POINT_EXPANSION} x the file size; ${this.used} bytes already used)`);
635
+ }
636
+ /** Reserves `bytes` for an allocation that lives until the decode ends. */
637
+ charge(bytes, what) {
638
+ if (bytes > this.limit - this.used)
639
+ this.fail(bytes, what);
640
+ this.used += bytes;
641
+ }
642
+ /** Checks a short-lived allocation against the budget left. */
643
+ check(bytes, what) {
644
+ if (bytes > this.limit - this.used)
645
+ this.fail(bytes, what);
646
+ }
647
+ }
648
+ /** The array's stored bytes (decompressed), checked to be exactly `expectedBytes`. */
649
+ function arrayBytes(array, expectedBytes, ctx) {
650
+ if (array.isPaged) {
651
+ if (array.bytes !== expectedBytes) {
652
+ throw new VdbFormatError(`paged point attribute holds ${array.bytes} bytes, expected ${expectedBytes}`);
653
+ }
654
+ const page = array.page;
655
+ if (!page?.data)
656
+ throw new VdbFormatError("paged point attribute has no page body");
657
+ let decoded = page.compressedBytes > 0 ? ctx.pages.get(page) : page.data;
658
+ if (!decoded) {
659
+ ctx.budget.charge(Math.max(page.uncompressedBytes, BLOSC_PAD_BYTES), "a point attribute page");
660
+ decoded = decompressExact(page.data, page.uncompressedBytes, "point attribute page");
661
+ ctx.pages.set(page, decoded);
662
+ }
663
+ if (array.pageOffset + expectedBytes > decoded.length) {
664
+ throw new VdbFormatError(`paged point attribute runs past its ${decoded.length}-byte page`);
665
+ }
666
+ return { bytes: decoded, offset: array.pageOffset };
667
+ }
668
+ if (!array.raw)
669
+ throw new VdbFormatError("point attribute has no buffer");
670
+ if (array.bloscCompressed) {
671
+ ctx.budget.check(expectedBytes, "a point attribute buffer");
672
+ return { bytes: decompressExact(array.raw, expectedBytes, "point attribute"), offset: 0 };
673
+ }
674
+ if (array.raw.length !== expectedBytes) {
675
+ throw new VdbFormatError(`point attribute holds ${array.raw.length} bytes, expected ${expectedBytes}`);
676
+ }
677
+ return { bytes: array.raw, offset: 0 };
678
+ }
679
+ /** Sorted attribute indices of the group arrays (`Descriptor::groupIndex`). */
680
+ function groupArrayIndices(descriptor) {
681
+ return descriptor.attributes
682
+ .filter((a) => a.type === "uint8" && a.codec === "grp")
683
+ .map((a) => a.index)
684
+ .sort((a, b) => a - b);
685
+ }
686
+ /**
687
+ * Decodes the points of a parsed point data grid: world-space positions from
688
+ * `P` (through `matrix`, a row-major 4x4 index->world transform) and every
689
+ * other attribute the codec table covers.
690
+ */
691
+ export function decodePoints(leaves, matrix, options = {}) {
692
+ const ctx = {
693
+ budget: new DecodeBudget(options.maxOutputBytes ?? Number.POSITIVE_INFINITY),
694
+ pages: new Map(),
695
+ };
696
+ let count = 0;
697
+ for (const leaf of leaves)
698
+ count += leaf.offsets[LEAF_NUM_VALUES - 1];
699
+ ctx.budget.charge(count * POSITION_BYTES, "point positions");
700
+ const positions = new Float32Array(count * 3);
701
+ const attributes = {};
702
+ const attributeShapes = {};
703
+ const groups = {};
704
+ const skipped = [];
705
+ const skippedNames = new Set();
706
+ const skip = (info) => {
707
+ if (skippedNames.has(info.name))
708
+ return;
709
+ skippedNames.add(info.name);
710
+ skipped.push(info);
711
+ };
712
+ const m = matrix;
713
+ let base = 0;
714
+ for (const leaf of leaves) {
715
+ const leafCount = leaf.offsets[LEAF_NUM_VALUES - 1];
716
+ const { descriptor, arrays } = leaf;
717
+ // Positions: voxel ijk + P offset, then index -> world.
718
+ const pInfo = descriptor.attributes.find((a) => a.name === "P");
719
+ // f32 offsets (every OpenVDB P codec but vec3d/null) decode in place into
720
+ // `positions`, then each point is transformed over its own offset.
721
+ let p = null;
722
+ let pAt = 0;
723
+ if (pInfo) {
724
+ const codec = attributeCodec(pInfo.type, pInfo.codec);
725
+ if (!codec || codec.components !== 3) {
726
+ throw new VDBUnsupportedError(`point position attribute P is ${pInfo.type}/${pInfo.codec}`);
727
+ }
728
+ if (codec.output === Float32Array) {
729
+ decodeArrayInto(arrays[pInfo.index], codec, leafCount, pInfo, ctx, positions, base * 3);
730
+ p = positions;
731
+ pAt = base * 3;
732
+ }
733
+ else {
734
+ ctx.budget.check(leafCount * 3 * codec.output.BYTES_PER_ELEMENT, "a leaf's point offsets");
735
+ const offsets = new codec.output(leafCount * 3);
736
+ decodeArrayInto(arrays[pInfo.index], codec, leafCount, pInfo, ctx, offsets, 0);
737
+ p = offsets;
738
+ }
739
+ }
740
+ let voxel = 0;
741
+ for (let i = 0; i < leafCount; i++) {
742
+ while (leaf.offsets[voxel] <= i)
743
+ voxel++;
744
+ const ix = leaf.origin[0] + (voxel >> (2 * LEAF_LOG2DIM));
745
+ const iy = leaf.origin[1] + ((voxel >> LEAF_LOG2DIM) & 7);
746
+ const iz = leaf.origin[2] + (voxel & 7);
747
+ const x = ix + (p ? p[pAt + i * 3] : 0);
748
+ const y = iy + (p ? p[pAt + i * 3 + 1] : 0);
749
+ const z = iz + (p ? p[pAt + i * 3 + 2] : 0);
750
+ const out = (base + i) * 3;
751
+ positions[out] = m[0] * x + m[1] * y + m[2] * z + m[3];
752
+ positions[out + 1] = m[4] * x + m[5] * y + m[6] * z + m[7];
753
+ positions[out + 2] = m[8] * x + m[9] * y + m[10] * z + m[11];
754
+ }
755
+ // Other attributes, decoded straight into the grid-wide output.
756
+ for (const info of descriptor.attributes) {
757
+ if (info.name === "P" || (info.type === "uint8" && info.codec === "grp"))
758
+ continue;
759
+ const codec = attributeCodec(info.type, info.codec);
760
+ const array = arrays[info.index];
761
+ const stride = arrayStride(array);
762
+ if (!codec || stride === null) {
763
+ skip(info);
764
+ continue;
765
+ }
766
+ let target = attributes[info.name];
767
+ const shape = attributeShapes[info.name];
768
+ if (!target) {
769
+ const length = count * stride * codec.components;
770
+ ctx.budget.charge(length * codec.output.BYTES_PER_ELEMENT, `point attribute "${info.name}"`);
771
+ target = new codec.output(length);
772
+ attributes[info.name] = target;
773
+ attributeShapes[info.name] = { components: codec.components, stride };
774
+ }
775
+ else if (!shape ||
776
+ shape.components !== codec.components ||
777
+ shape.stride !== stride ||
778
+ target.constructor !== codec.output) {
779
+ throw new VDBUnsupportedError(`point attribute "${info.name}" changes type between leaves`);
780
+ }
781
+ decodeArrayInto(array, codec, leafCount * stride, info, ctx, target, base * stride * codec.components);
782
+ }
783
+ // Groups: one bit per point in the uint8 group arrays (`Descriptor::groupIndex`).
784
+ if (descriptor.groups.length > 0) {
785
+ const groupArrays = groupArrayIndices(descriptor);
786
+ const decodedGroups = new Map();
787
+ const uint8 = attributeCodec("uint8", "null");
788
+ for (const { name, offset } of descriptor.groups) {
789
+ if (offset >= groupArrays.length * 8) {
790
+ throw new VdbFormatError(`point group "${name}" offset ${offset} is out of range`);
791
+ }
792
+ const arrayIndex = groupArrays[Math.floor(offset / 8)];
793
+ let bits = decodedGroups.get(arrayIndex);
794
+ if (!bits) {
795
+ ctx.budget.check(leafCount, "a leaf's group bits");
796
+ bits = new Uint8Array(leafCount);
797
+ decodeArrayInto(arrays[arrayIndex], uint8, leafCount, descriptor.attributes[arrayIndex], ctx, bits, 0);
798
+ decodedGroups.set(arrayIndex, bits);
799
+ }
800
+ let target = groups[name];
801
+ if (!target) {
802
+ ctx.budget.charge(count, `point group "${name}"`);
803
+ target = groups[name] = new Uint8Array(count);
804
+ }
805
+ const bit = offset % 8;
806
+ for (let i = 0; i < leafCount; i++)
807
+ target[base + i] = (bits[i] >> bit) & 1;
808
+ }
809
+ }
810
+ base += leafCount;
811
+ options.onProgress?.(base, count);
812
+ }
813
+ if (leaves.length === 0)
814
+ options.onProgress?.(0, 0);
815
+ return { count, positions, attributes, attributeShapes, groups, skipped };
816
+ }
817
+ /**
818
+ * Decodes `elements` elements of one leaf array into `out` from `outAt` (a
819
+ * uniform array repeats its single value). The array's size and stride are
820
+ * checked before any byte is read.
821
+ */
822
+ function decodeArrayInto(array, codec, elements, info, ctx, out, outAt) {
823
+ const stride = arrayStride(array) ?? 1;
824
+ if (array.size * stride !== elements) {
825
+ throw new VdbFormatError(`point attribute "${info.name}" holds ${array.size} x ${stride} values, but the leaf has ${elements / stride} points`);
826
+ }
827
+ const stored = array.isUniform ? 1 : elements;
828
+ const storedBytes = stored * codec.storageBytes;
829
+ const { bytes, offset } = arrayBytes(array, storedBytes, ctx);
830
+ const view = new DataView(bytes.buffer, bytes.byteOffset + offset, storedBytes);
831
+ for (let i = 0; i < elements; i++) {
832
+ codec.decode(view, array.isUniform ? 0 : i * codec.storageBytes, out, outAt + i * codec.components);
833
+ }
834
+ }
835
+ //# sourceMappingURL=points.js.map