@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,239 @@
1
+ /**
2
+ * CPU twins (D11) of the core compute tools (K2.3, `core/compute/`):
3
+ * `vdbGridStatsCpu` (twin of `gridStats`), `vdbDecodeToAtlasCpu` (twin of
4
+ * `decodeToAtlas`) and `transformLeafValues`, the CPU value transform that
5
+ * `vdbApplyValueTransform` writes back with `pool.replace` (it is also the twin of
6
+ * v1's GPU `valueTransform`, which the pool's read-only binding retired).
7
+ *
8
+ * The shared pure pieces live here so the core and its twins cannot drift:
9
+ * `atlasDims` (output resolution), `atlasFromRaw` (normalize / quantize after
10
+ * readback) and `rootStats` (the range both tools use).
11
+ *
12
+ * Float arithmetic: each WGSL f32 operation is rounded with `Math.fround` in
13
+ * the WGSL's order. WGSL allows a 2.5 ULP division and fused multiply-adds,
14
+ * so GPU parity compares with a tolerance and reports the bit-exact count.
15
+ */
16
+ import { VDBToolsError } from "../errors.js";
17
+ import { vdbFloatToHalf, vdbHalfToFloat } from "../nanovdb/half.js";
18
+ import { indexBBox, isActive, vdbReadValueF32Cpu, treeNodes } from "./march.js";
19
+ import { defineNumber, gridTypeConstantsFor, gridTypeConstantsForId, gridTypeIds } from "./stride-tables.js";
20
+ const f = Math.fround;
21
+ const GRID_OFF_GRID_TYPE = defineNumber("PNANOVDB_GRID_OFF_GRID_TYPE");
22
+ const GRID_SIZE = defineNumber("PNANOVDB_GRID_SIZE");
23
+ const TREE_OFF_NODE_OFFSET_ROOT = defineNumber("PNANOVDB_TREE_OFF_NODE_OFFSET_ROOT");
24
+ /** Fixed-point scale of the GPU fast path's 64-bit sum (2^20). */
25
+ export const GRID_STATS_SUM_SCALE = 1048576;
26
+ /** Per-axis voxel count of an inclusive-max index bbox (`max - min + 1`). */
27
+ export function bboxSize(bbox) {
28
+ return [bbox.max[0] - bbox.min[0] + 1, bbox.max[1] - bbox.min[1] + 1, bbox.max[2] - bbox.min[2] + 1];
29
+ }
30
+ /**
31
+ * `decodeToAtlas` output resolution: each axis of the index bbox clamped to
32
+ * `maxDim` (a literal per-axis clamp, not a proportional downscale; v1).
33
+ */
34
+ export function atlasDims(bbox, maxDim) {
35
+ const [sx, sy, sz] = bboxSize(bbox);
36
+ return [Math.min(sx, maxDim), Math.min(sy, maxDim), Math.min(sz, maxDim)];
37
+ }
38
+ /** The root node's stored min/max statistics (f32; binary16 decoded for Half), meaningful when the grid has stats. */
39
+ export function rootStats(gridWords) {
40
+ const gridType = gridWords[GRID_OFF_GRID_TYPE >>> 2];
41
+ const gt = gridTypeConstantsForId(gridType);
42
+ const root = GRID_SIZE + gridWords[(GRID_SIZE + TREE_OFF_NODE_OFFSET_ROOT) >>> 2];
43
+ if (gridType === gridTypeIds.HALF) {
44
+ const half = (address) => vdbHalfToFloat(gridWords[address >>> 2] >>> ((address & 2) << 3));
45
+ return { min: half(root + gt.root_off_min), max: half(root + gt.root_off_max) };
46
+ }
47
+ const f32 = new Float32Array(gridWords.buffer, gridWords.byteOffset, gridWords.length);
48
+ return { min: f32[(root + gt.root_off_min) >>> 2], max: f32[(root + gt.root_off_max) >>> 2] };
49
+ }
50
+ /**
51
+ * Twin of `gridStats`: min, max, mean and a histogram over the ACTIVE voxels of
52
+ * the dense index bbox, read as the GPU reads them (`vdbIsActive`,
53
+ * `vdbReadValue`). The histogram spans the root statistics `[rootMin,
54
+ * rootMax]`.
55
+ *
56
+ * Both GPU paths are reproduced: the atomics path (root min ≥ 0) normalizes in
57
+ * f32 and sums `u32(norm * 2^20)` in a 64-bit integer; the dump path (root min
58
+ * < 0) reduces f32 values in f64 on the CPU. The f32 normalization divides, so
59
+ * a GPU with an inexact division may put a voxel in the neighbouring bin or
60
+ * shift the mean by a fixed-point step.
61
+ *
62
+ * @param gridWords The grid image (little-endian u32 words, `GridData` at word 0).
63
+ * @param options Histogram bin count.
64
+ */
65
+ export function vdbGridStatsCpu(gridWords, options = {}) {
66
+ const bins = options.histogramBins ?? 256;
67
+ const range = rootStats(gridWords);
68
+ const fast = range.min >= 0;
69
+ const { min: lo, max: hi } = indexBBox(gridWords);
70
+ const histogram = new Uint32Array(bins);
71
+ let min = Infinity;
72
+ let max = -Infinity;
73
+ let count = 0;
74
+ let sumFixed = 0n;
75
+ let sum = 0;
76
+ const spanF = f(Math.max(f(range.max - range.min), f(1e-20)));
77
+ const spanD = Math.max(range.max - range.min, 1e-20);
78
+ const ijk = [0, 0, 0];
79
+ for (let z = lo[2]; z <= hi[2]; z++) {
80
+ for (let y = lo[1]; y <= hi[1]; y++) {
81
+ for (let x = lo[0]; x <= hi[0]; x++) {
82
+ ijk[0] = x;
83
+ ijk[1] = y;
84
+ ijk[2] = z;
85
+ if (!isActive(gridWords, ijk))
86
+ continue;
87
+ const v = vdbReadValueF32Cpu(gridWords, ijk);
88
+ count++;
89
+ if (v < min)
90
+ min = v;
91
+ if (v > max)
92
+ max = v;
93
+ let norm;
94
+ if (fast) {
95
+ norm = Math.min(Math.max(f(f(v - range.min) / spanF), 0), 1);
96
+ sumFixed += BigInt(Math.trunc(f(norm * GRID_STATS_SUM_SCALE)));
97
+ histogram[Math.min(Math.trunc(f(norm * bins)), bins - 1)]++;
98
+ }
99
+ else {
100
+ sum += v;
101
+ norm = Math.min(Math.max((v - range.min) / spanD, 0), 1);
102
+ histogram[Math.min(Math.floor(norm * bins), bins - 1)]++;
103
+ }
104
+ }
105
+ }
106
+ }
107
+ if (count === 0)
108
+ return { min: 0, max: 0, mean: 0, histogram, activeVoxelCount: 0, usedAtomicFastPath: fast, range };
109
+ // The GPU's 64-bit sum wraps like a u64.
110
+ sumFixed &= (1n << 64n) - 1n;
111
+ const mean = fast
112
+ ? range.min + (Number(sumFixed) / (GRID_STATS_SUM_SCALE * count)) * (range.max - range.min)
113
+ : sum / count;
114
+ return { min, max, mean, histogram, activeVoxelCount: count, usedAtomicFastPath: fast, range };
115
+ }
116
+ /**
117
+ * Post-readback step of `decodeToAtlas` (v1, in f64): `uint8` maps `[min,
118
+ * max]` to `[0, 255]` with `Math.round` (or clamps the raw value when not
119
+ * normalizing); `float32` maps to `[0, 1]` or returns `raw` itself.
120
+ */
121
+ export function atlasFromRaw(raw, o) {
122
+ const n = raw.length;
123
+ const span = Math.max(o.range.max - o.range.min, 1e-20);
124
+ if (o.format === "uint8") {
125
+ const out = new Uint8Array(n);
126
+ if (o.normalize) {
127
+ for (let i = 0; i < n; i++)
128
+ out[i] = Math.round(Math.min(Math.max((raw[i] - o.range.min) / span, 0), 1) * 255);
129
+ }
130
+ else {
131
+ for (let i = 0; i < n; i++)
132
+ out[i] = Math.min(Math.max(Math.round(raw[i]), 0), 255);
133
+ }
134
+ return out;
135
+ }
136
+ if (!o.normalize)
137
+ return raw;
138
+ const out = new Float32Array(n);
139
+ for (let i = 0; i < n; i++)
140
+ out[i] = Math.min(Math.max((raw[i] - o.range.min) / span, 0), 1);
141
+ return out;
142
+ }
143
+ /**
144
+ * Twin of the `decodeToAtlas` pass before normalization: one f32 per output
145
+ * voxel (x fastest), sampled at index position `min + (i + 0.5) * size / dims
146
+ * - 0.5` (cell `i` of `dims` over `[min, max]`, `size = max - min + 1`; voxel
147
+ * centres at full resolution, K2.6) with `vdbReadValue(floor(p + 0.5))` (`'nearest'`) or
148
+ * the vendored trilinear (`'trilinear'`, the default). Feed the result to
149
+ * {@link atlasFromRaw} for the formatted atlas.
150
+ *
151
+ * @param gridWords The grid image (little-endian u32 words, `GridData` at word 0).
152
+ * @param options Longest atlas side and filter.
153
+ */
154
+ export function vdbDecodeToAtlasCpu(gridWords, options = {}) {
155
+ const bbox = indexBBox(gridWords);
156
+ const size = bboxSize(bbox);
157
+ const dims = atlasDims(bbox, options.maxDim ?? 256);
158
+ const trilinear = (options.filter ?? "trilinear") === "trilinear";
159
+ const raw = new Float32Array(dims[0] * dims[1] * dims[2]);
160
+ const pos = [0, 0, 0];
161
+ let i = 0;
162
+ for (let z = 0; z < dims[2]; z++) {
163
+ for (let y = 0; y < dims[1]; y++) {
164
+ for (let x = 0; x < dims[0]; x++) {
165
+ const g = [x, y, z];
166
+ for (let a = 0; a < 3; a++)
167
+ pos[a] = f(bbox.min[a] + f(f(f(f(g[a] + 0.5) * size[a]) / dims[a]) - 0.5));
168
+ raw[i++] = trilinear ? trilinearF32(gridWords, pos) : vdbReadValueF32Cpu(gridWords, [Math.floor(f(pos[0] + 0.5)), Math.floor(f(pos[1] + 0.5)), Math.floor(f(pos[2] + 0.5))]);
169
+ }
170
+ }
171
+ }
172
+ return { raw, dims };
173
+ }
174
+ /** The vendored `sample_trilinear_typed` in f32: `mix(a, b, t)` as `a + t * (b - a)`. */
175
+ function trilinearF32(gridWords, xyz) {
176
+ const b = [Math.floor(xyz[0]), Math.floor(xyz[1]), Math.floor(xyz[2])];
177
+ const u = [f(xyz[0] - b[0]), f(xyz[1] - b[1]), f(xyz[2] - b[2])];
178
+ const tap = (dx, dy, dz) => vdbReadValueF32Cpu(gridWords, [b[0] + dx, b[1] + dy, b[2] + dz]);
179
+ const mix = (a, c, t) => f(a + f(t * f(c - a)));
180
+ const x00 = mix(tap(0, 0, 0), tap(1, 0, 0), u[0]);
181
+ const x10 = mix(tap(0, 1, 0), tap(1, 1, 0), u[0]);
182
+ const x01 = mix(tap(0, 0, 1), tap(1, 0, 1), u[0]);
183
+ const x11 = mix(tap(0, 1, 1), tap(1, 1, 1), u[0]);
184
+ return mix(mix(x00, x10, u[1]), mix(x01, x11, u[1]), u[2]);
185
+ }
186
+ // ---------------------------------------------------------------------------
187
+ // Value transform
188
+ /**
189
+ * Returns a copy of a Float or Half grid image with `fn` applied to every leaf
190
+ * voxel value inside the index bbox (active or inactive), rounded to f32 (and,
191
+ * in a Half grid, then to the nearest binary16 as `vdbFloatToHalf` does; K7.H1). Tile,
192
+ * background and out-of-bbox leaf values are left alone, exactly as v1's GPU
193
+ * `valueTransform` did (it visited the dense bbox and rewrote level-0
194
+ * addresses only).
195
+ *
196
+ * The image's statistics (root/node min, max, average, deviation) are NOT
197
+ * recomputed: they describe the source values. Tools that trust them
198
+ * (`gridStats`' range, `vdbNodeMax` skipping) see stale bounds; rebuild the
199
+ * grid (e.g. `vdbBuildFromDense`) when they matter.
200
+ *
201
+ * Float and Half only: quantized (Fp*) leaves would need re-encoding.
202
+ */
203
+ export function transformLeafValues(gridWords, fn) {
204
+ if (typeof fn !== "function")
205
+ throw new VDBToolsError("VDB_BAD_OPTION", "transformLeafValues: fn must be a function (value: number) => number");
206
+ const gridType = gridWords[GRID_OFF_GRID_TYPE >>> 2];
207
+ const half = gridType === gridTypeIds.HALF;
208
+ if (gridType !== gridTypeIds.FLOAT && !half) {
209
+ throw new VDBToolsError("VDB_UNSUPPORTED_GRID_TYPE", `transformLeafValues: grid type ${gridType} is not Float (${gridTypeIds.FLOAT}) or Half (${gridTypeIds.HALF}); quantized leaves would need re-encoding. ` +
210
+ "Transform the Float source and quantize() afterwards.");
211
+ }
212
+ const out = gridWords.slice();
213
+ const outF32 = new Float32Array(out.buffer, out.byteOffset, out.length);
214
+ const outU16 = new Uint16Array(out.buffer, out.byteOffset, out.length * 2);
215
+ const table = gridTypeConstantsFor(half ? "HALF" : "FLOAT").leaf_off_table;
216
+ const { min, max } = indexBBox(gridWords);
217
+ for (const node of treeNodes(gridWords)) {
218
+ if (node.level !== 0)
219
+ continue;
220
+ const [ox, oy, oz] = node.origin;
221
+ for (let n = 0; n < 512; n++) {
222
+ const x = ox + (n >> 6);
223
+ const y = oy + ((n >> 3) & 7);
224
+ const z = oz + (n & 7);
225
+ if (x < min[0] || y < min[1] || z < min[2] || x > max[0] || y > max[1] || z > max[2])
226
+ continue;
227
+ if (half) {
228
+ const at = (node.address + table + 2 * n) >>> 1;
229
+ outU16[at] = vdbFloatToHalf(f(fn(vdbHalfToFloat(outU16[at]))));
230
+ }
231
+ else {
232
+ const word = (node.address + table + 4 * n) >>> 2;
233
+ outF32[word] = f(fn(outF32[word]));
234
+ }
235
+ }
236
+ }
237
+ return out;
238
+ }
239
+ //# sourceMappingURL=compute.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compute.js","sourceRoot":"","sources":["../../../src/tools/cpu/compute.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,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ute tools (K2.3, `core/compute/`):\n * `vdbGridStatsCpu` (twin of `gridStats`), `vdbDecodeToAtlasCpu` (twin of\n * `decodeToAtlas`) and `transformLeafValues`, the CPU value transform that\n * `vdbApplyValueTransform` writes back with `pool.replace` (it is also the twin of\n * v1's GPU `valueTransform`, which the pool's read-only binding retired).\n *\n * The shared pure pieces live here so the core and its twins cannot drift:\n * `atlasDims` (output resolution), `atlasFromRaw` (normalize / quantize after\n * readback) and `rootStats` (the range both tools use).\n *\n * Float arithmetic: each WGSL f32 operation is rounded with `Math.fround` in\n * the WGSL's order. WGSL allows a 2.5 ULP division and fused multiply-adds,\n * so GPU parity compares with a tolerance and reports the bit-exact count.\n */\nimport { VDBToolsError } from \"../errors.js\";\nimport { vdbFloatToHalf, vdbHalfToFloat } from \"../nanovdb/half.js\";\nimport { indexBBox, isActive, vdbReadValueF32Cpu, treeNodes, type Vec3 } from \"./march.js\";\nimport { defineNumber, gridTypeConstantsFor, gridTypeConstantsForId, gridTypeIds } from \"./stride-tables.js\";\n\nconst f = Math.fround;\n\nconst GRID_OFF_GRID_TYPE = defineNumber(\"PNANOVDB_GRID_OFF_GRID_TYPE\");\nconst GRID_SIZE = defineNumber(\"PNANOVDB_GRID_SIZE\");\nconst TREE_OFF_NODE_OFFSET_ROOT = defineNumber(\"PNANOVDB_TREE_OFF_NODE_OFFSET_ROOT\");\n\n/** Fixed-point scale of the GPU fast path's 64-bit sum (2^20). */\nexport const GRID_STATS_SUM_SCALE = 1048576;\n\n/** Index bbox, inclusive on both ends. */\nexport interface IndexBBox {\n min: readonly [number, number, number];\n max: readonly [number, number, number];\n}\n\n/** Per-axis voxel count of an inclusive-max index bbox (`max - min + 1`). */\nexport function bboxSize(bbox: IndexBBox): [number, number, number] {\n return [bbox.max[0] - bbox.min[0] + 1, bbox.max[1] - bbox.min[1] + 1, bbox.max[2] - bbox.min[2] + 1];\n}\n\n/**\n * `decodeToAtlas` output resolution: each axis of the index bbox clamped to\n * `maxDim` (a literal per-axis clamp, not a proportional downscale; v1).\n */\nexport function atlasDims(bbox: IndexBBox, maxDim: number): [number, number, number] {\n const [sx, sy, sz] = bboxSize(bbox);\n return [Math.min(sx, maxDim), Math.min(sy, maxDim), Math.min(sz, maxDim)];\n}\n\n/** The root node's stored min/max statistics (f32; binary16 decoded for Half), meaningful when the grid has stats. */\nexport function rootStats(gridWords: Uint32Array): { min: number; max: number } {\n const gridType = gridWords[GRID_OFF_GRID_TYPE >>> 2]!;\n const gt = gridTypeConstantsForId(gridType);\n const root = GRID_SIZE + gridWords[(GRID_SIZE + TREE_OFF_NODE_OFFSET_ROOT) >>> 2]!;\n if (gridType === gridTypeIds.HALF) {\n const half = (address: number) => vdbHalfToFloat(gridWords[address >>> 2]! >>> ((address & 2) << 3));\n return { min: half(root + gt.root_off_min), max: half(root + gt.root_off_max) };\n }\n const f32 = new Float32Array(gridWords.buffer, gridWords.byteOffset, gridWords.length);\n return { min: f32[(root + gt.root_off_min) >>> 2]!, max: f32[(root + gt.root_off_max) >>> 2]! };\n}\n\n// ---------------------------------------------------------------------------\n// gridStats\n\n/** Options of {@link vdbGridStatsCpu}. */\nexport interface VDBGridStatsCpuOptions {\n /** Histogram bins (default 256). */\n histogramBins?: number;\n}\n\n/** Result of {@link vdbGridStatsCpu}, the twin of the GPU `gridStats` result. */\nexport interface VDBGridStatsCpuResult {\n /** Smallest active value. */\n min: number;\n /** Largest active value. */\n max: number;\n /** Mean of the active values. */\n mean: number;\n /** Counts of active voxels per bin over {@link range}. */\n histogram: Uint32Array;\n /** Number of active voxels in the index bbox. */\n activeVoxelCount: number;\n /** The path the GPU takes for this grid: `true` when the root min is ≥ 0 (atomics). */\n usedAtomicFastPath: boolean;\n /** The histogram range: the root min/max statistics. */\n range: { min: number; max: number };\n}\n\n/**\n * Twin of `gridStats`: min, max, mean and a histogram over the ACTIVE voxels of\n * the dense index bbox, read as the GPU reads them (`vdbIsActive`,\n * `vdbReadValue`). The histogram spans the root statistics `[rootMin,\n * rootMax]`.\n *\n * Both GPU paths are reproduced: the atomics path (root min ≥ 0) normalizes in\n * f32 and sums `u32(norm * 2^20)` in a 64-bit integer; the dump path (root min\n * < 0) reduces f32 values in f64 on the CPU. The f32 normalization divides, so\n * a GPU with an inexact division may put a voxel in the neighbouring bin or\n * shift the mean by a fixed-point step.\n *\n * @param gridWords The grid image (little-endian u32 words, `GridData` at word 0).\n * @param options Histogram bin count.\n */\nexport function vdbGridStatsCpu(gridWords: Uint32Array, options: VDBGridStatsCpuOptions = {}): VDBGridStatsCpuResult {\n const bins = options.histogramBins ?? 256;\n const range = rootStats(gridWords);\n const fast = range.min >= 0;\n const { min: lo, max: hi } = indexBBox(gridWords);\n const histogram = new Uint32Array(bins);\n let min = Infinity;\n let max = -Infinity;\n let count = 0;\n let sumFixed = 0n;\n let sum = 0;\n const spanF = f(Math.max(f(range.max - range.min), f(1e-20)));\n const spanD = Math.max(range.max - range.min, 1e-20);\n const ijk: Vec3 = [0, 0, 0];\n for (let z = lo[2]; z <= hi[2]; z++) {\n for (let y = lo[1]; y <= hi[1]; y++) {\n for (let x = lo[0]; x <= hi[0]; x++) {\n ijk[0] = x;\n ijk[1] = y;\n ijk[2] = z;\n if (!isActive(gridWords, ijk)) continue;\n const v = vdbReadValueF32Cpu(gridWords, ijk);\n count++;\n if (v < min) min = v;\n if (v > max) max = v;\n let norm: number;\n if (fast) {\n norm = Math.min(Math.max(f(f(v - range.min) / spanF), 0), 1);\n sumFixed += BigInt(Math.trunc(f(norm * GRID_STATS_SUM_SCALE)));\n histogram[Math.min(Math.trunc(f(norm * bins)), bins - 1)]!++;\n } else {\n sum += v;\n norm = Math.min(Math.max((v - range.min) / spanD, 0), 1);\n histogram[Math.min(Math.floor(norm * bins), bins - 1)]!++;\n }\n }\n }\n }\n if (count === 0) return { min: 0, max: 0, mean: 0, histogram, activeVoxelCount: 0, usedAtomicFastPath: fast, range };\n // The GPU's 64-bit sum wraps like a u64.\n sumFixed &= (1n << 64n) - 1n;\n const mean = fast\n ? range.min + (Number(sumFixed) / (GRID_STATS_SUM_SCALE * count)) * (range.max - range.min)\n : sum / count;\n return { min, max, mean, histogram, activeVoxelCount: count, usedAtomicFastPath: fast, range };\n}\n\n// ---------------------------------------------------------------------------\n// decodeToAtlas\n\n/** How an atlas samples the grid: the nearest voxel or trilinear interpolation. */\nexport type VDBAtlasFilter = \"nearest\" | \"trilinear\";\n/** Texel format of a decoded atlas: 8-bit unsigned or 32-bit float. */\nexport type VDBAtlasFormat = \"uint8\" | \"float32\";\n\nexport interface AtlasFromRawOptions {\n format: VDBAtlasFormat;\n normalize: boolean;\n range: { min: number; max: number };\n}\n\n/**\n * Post-readback step of `decodeToAtlas` (v1, in f64): `uint8` maps `[min,\n * max]` to `[0, 255]` with `Math.round` (or clamps the raw value when not\n * normalizing); `float32` maps to `[0, 1]` or returns `raw` itself.\n */\nexport function atlasFromRaw(raw: Float32Array, o: AtlasFromRawOptions): Uint8Array | Float32Array {\n const n = raw.length;\n const span = Math.max(o.range.max - o.range.min, 1e-20);\n if (o.format === \"uint8\") {\n const out = new Uint8Array(n);\n if (o.normalize) {\n for (let i = 0; i < n; i++) out[i] = Math.round(Math.min(Math.max((raw[i]! - o.range.min) / span, 0), 1) * 255);\n } else {\n for (let i = 0; i < n; i++) out[i] = Math.min(Math.max(Math.round(raw[i]!), 0), 255);\n }\n return out;\n }\n if (!o.normalize) return raw;\n const out = new Float32Array(n);\n for (let i = 0; i < n; i++) out[i] = Math.min(Math.max((raw[i]! - o.range.min) / span, 0), 1);\n return out;\n}\n\n/** Options of {@link vdbDecodeToAtlasCpu}. */\nexport interface VDBDecodeToAtlasCpuOptions {\n /** Longest atlas side in texels (default 256). */\n maxDim?: number;\n /** Sampling filter (default `'trilinear'`). */\n filter?: VDBAtlasFilter;\n}\n\n/**\n * Twin of the `decodeToAtlas` pass before normalization: one f32 per output\n * voxel (x fastest), sampled at index position `min + (i + 0.5) * size / dims\n * - 0.5` (cell `i` of `dims` over `[min, max]`, `size = max - min + 1`; voxel\n * centres at full resolution, K2.6) with `vdbReadValue(floor(p + 0.5))` (`'nearest'`) or\n * the vendored trilinear (`'trilinear'`, the default). Feed the result to\n * {@link atlasFromRaw} for the formatted atlas.\n *\n * @param gridWords The grid image (little-endian u32 words, `GridData` at word 0).\n * @param options Longest atlas side and filter.\n */\nexport function vdbDecodeToAtlasCpu(\n gridWords: Uint32Array,\n options: VDBDecodeToAtlasCpuOptions = {},\n): { raw: Float32Array; dims: [number, number, number] } {\n const bbox = indexBBox(gridWords);\n const size = bboxSize(bbox);\n const dims = atlasDims(bbox, options.maxDim ?? 256);\n const trilinear = (options.filter ?? \"trilinear\") === \"trilinear\";\n const raw = new Float32Array(dims[0] * dims[1] * dims[2]);\n const pos: Vec3 = [0, 0, 0];\n let i = 0;\n for (let z = 0; z < dims[2]; z++) {\n for (let y = 0; y < dims[1]; y++) {\n for (let x = 0; x < dims[0]; x++) {\n const g: Vec3 = [x, y, z];\n for (let a = 0; a < 3; a++) pos[a] = f(bbox.min[a]! + f(f(f(f(g[a]! + 0.5) * size[a]!) / dims[a]!) - 0.5));\n raw[i++] = trilinear ? trilinearF32(gridWords, pos) : vdbReadValueF32Cpu(gridWords, [Math.floor(f(pos[0] + 0.5)), Math.floor(f(pos[1] + 0.5)), Math.floor(f(pos[2] + 0.5))]);\n }\n }\n }\n return { raw, dims };\n}\n\n/** The vendored `sample_trilinear_typed` in f32: `mix(a, b, t)` as `a + t * (b - a)`. */\nfunction trilinearF32(gridWords: Uint32Array, xyz: Vec3): number {\n const b: Vec3 = [Math.floor(xyz[0]), Math.floor(xyz[1]), Math.floor(xyz[2])];\n const u = [f(xyz[0] - b[0]), f(xyz[1] - b[1]), f(xyz[2] - b[2])];\n const tap = (dx: number, dy: number, dz: number) => vdbReadValueF32Cpu(gridWords, [b[0] + dx, b[1] + dy, b[2] + dz]);\n const mix = (a: number, c: number, t: number) => f(a + f(t * f(c - a)));\n const x00 = mix(tap(0, 0, 0), tap(1, 0, 0), u[0]!);\n const x10 = mix(tap(0, 1, 0), tap(1, 1, 0), u[0]!);\n const x01 = mix(tap(0, 0, 1), tap(1, 0, 1), u[0]!);\n const x11 = mix(tap(0, 1, 1), tap(1, 1, 1), u[0]!);\n return mix(mix(x00, x10, u[1]!), mix(x01, x11, u[1]!), u[2]!);\n}\n\n// ---------------------------------------------------------------------------\n// Value transform\n\n/**\n * Returns a copy of a Float or Half grid image with `fn` applied to every leaf\n * voxel value inside the index bbox (active or inactive), rounded to f32 (and,\n * in a Half grid, then to the nearest binary16 as `vdbFloatToHalf` does; K7.H1). Tile,\n * background and out-of-bbox leaf values are left alone, exactly as v1's GPU\n * `valueTransform` did (it visited the dense bbox and rewrote level-0\n * addresses only).\n *\n * The image's statistics (root/node min, max, average, deviation) are NOT\n * recomputed: they describe the source values. Tools that trust them\n * (`gridStats`' range, `vdbNodeMax` skipping) see stale bounds; rebuild the\n * grid (e.g. `vdbBuildFromDense`) when they matter.\n *\n * Float and Half only: quantized (Fp*) leaves would need re-encoding.\n */\nexport function transformLeafValues(gridWords: Uint32Array, fn: (value: number) => number): Uint32Array {\n if (typeof fn !== \"function\") throw new VDBToolsError(\"VDB_BAD_OPTION\", \"transformLeafValues: fn must be a function (value: number) => number\");\n const gridType = gridWords[GRID_OFF_GRID_TYPE >>> 2];\n const half = gridType === gridTypeIds.HALF;\n if (gridType !== gridTypeIds.FLOAT && !half) {\n throw new VDBToolsError(\"VDB_UNSUPPORTED_GRID_TYPE\",\n `transformLeafValues: grid type ${gridType} is not Float (${gridTypeIds.FLOAT}) or Half (${gridTypeIds.HALF}); quantized leaves would need re-encoding. ` +\n \"Transform the Float source and quantize() afterwards.\",\n );\n }\n const out = gridWords.slice();\n const outF32 = new Float32Array(out.buffer, out.byteOffset, out.length);\n const outU16 = new Uint16Array(out.buffer, out.byteOffset, out.length * 2);\n const table = gridTypeConstantsFor(half ? \"HALF\" : \"FLOAT\").leaf_off_table;\n const { min, max } = indexBBox(gridWords);\n for (const node of treeNodes(gridWords)) {\n if (node.level !== 0) continue;\n const [ox, oy, oz] = node.origin;\n for (let n = 0; n < 512; n++) {\n const x = ox + (n >> 6);\n const y = oy + ((n >> 3) & 7);\n const z = oz + (n & 7);\n if (x < min[0] || y < min[1] || z < min[2] || x > max[0] || y > max[1] || z > max[2]) continue;\n if (half) {\n const at = (node.address + table + 2 * n) >>> 1;\n outU16[at] = vdbFloatToHalf(f(fn(vdbHalfToFloat(outU16[at]!))));\n } else {\n const word = (node.address + table + 4 * n) >>> 2;\n outF32[word] = f(fn(outF32[word]!));\n }\n }\n }\n return out;\n}\n"]}
@@ -0,0 +1,81 @@
1
+ /** What the lean accessor caches (the module option `cache`). */
2
+ export type LeanCache = "leaf" | "lower" | "lowerLeaf";
3
+ /** Options of {@link LeanReadCounter}: the module options that change what a read loads. */
4
+ export interface LeanReadOptions {
5
+ /** The accessor cache. Default `'leaf'`. */
6
+ cache?: LeanCache;
7
+ /** `'zero'`: taps outside the index bbox read 0 without a load, and an init reads the bbox. Default `'background'`. */
8
+ outside?: "background" | "zero";
9
+ /** Grid types the module compiles: with 1 (default) the unchecked init does not read the record's type. */
10
+ compiledTypes?: number;
11
+ }
12
+ /** The lean `VdbAccessor`. */
13
+ export interface LeanAccessor {
14
+ ok: boolean;
15
+ /** Leaf cache: origin (`ijk & -8`) and byte address (0 = none); with cache `'lower'` the lower node (`ijk & -128`). */
16
+ lk: [number, number, number];
17
+ la: number;
18
+ /** `'lowerLeaf'`: the lower node. */
19
+ qk: [number, number, number];
20
+ qa: number;
21
+ }
22
+ /** Loads since the last {@link LeanReadCounter.reset}. */
23
+ export interface LeanReadCounts {
24
+ /** Pool-table words (the grid count and the grid's record). */
25
+ table: number;
26
+ /** Words of the grid image. */
27
+ image: number;
28
+ /** Different words among them (a word loaded twice counts once). */
29
+ distinct: number;
30
+ }
31
+ /** The lean reader on one grid image, counting loads. */
32
+ export declare class LeanReadCounter {
33
+ readonly image: Uint32Array;
34
+ readonly cache: LeanCache;
35
+ readonly zero: boolean;
36
+ readonly gridType: number;
37
+ private readonly compiledTypes;
38
+ private readonly lo;
39
+ private readonly hi;
40
+ private table;
41
+ private loads;
42
+ private readonly seen;
43
+ constructor(image: Uint32Array, options?: LeanReadOptions);
44
+ /** Forget the loads counted so far. */
45
+ reset(): void;
46
+ /** Loads since the last `reset()`. */
47
+ get counts(): LeanReadCounts;
48
+ private rec;
49
+ /** `vdb_ln_w`. */
50
+ private w;
51
+ private bit;
52
+ /** `vdb_live(g)`: the grid count and the record's flags. */
53
+ private live;
54
+ private root;
55
+ /**
56
+ * `vdbAccessorInit(g)` (`'checked'`) or the helper `vdbAccessorInitUnchecked(g)`.
57
+ * Checked: `vdbGridType` (live check, type), the image offset, the root offset (an image word) and, with
58
+ * `outside: 'zero'`, `vdbIndexMin` and `vdbIndexMax` (a live check and 3 words each).
59
+ * Unchecked: the type (only in a module of several types), the image offset, the root offset, the 6 bbox words.
60
+ */
61
+ accessor(init?: "checked" | "unchecked"): LeanAccessor;
62
+ /** `vdb_ln_lower`: (address, level) with level 1 the lower node, 2 upper tile, 3 root tile, 4 background; then (mask word address, bit). */
63
+ private lower;
64
+ /** `vdb_ln_down`: the lower node's child lookup: (address, level 0 leaf / 1 lower tile, mask word address, bit). */
65
+ private down;
66
+ /** `vdb_ln_find`: the whole descent. */
67
+ private find;
68
+ private f32;
69
+ /** `vdb_ln_tile`: a tile or background slot. */
70
+ private tile;
71
+ /** `vdb_ln_leaf`: voxel `n` of the leaf at `l`. */
72
+ private leaf;
73
+ private differs;
74
+ /** `vdbReadValue(&acc, ijk)`. */
75
+ readValue(acc: LeanAccessor, ijk: readonly [number, number, number]): number;
76
+ /** `vdbIsActive(&acc, ijk)` (no cache: a walk from the root every time). */
77
+ isActive(acc: LeanAccessor, ijk: readonly [number, number, number]): boolean;
78
+ private tap;
79
+ /** `vdbSample(&acc, xyz)`, trilinear (and `vdbSampleFast`, the same function under the lean reader). */
80
+ sample(acc: LeanAccessor, xyz: readonly [number, number, number]): number;
81
+ }
@@ -0,0 +1,262 @@
1
+ /**
2
+ * P1.16: an instrumented twin of the lean reader (`core/wgsl/lean.ts`, `reader: 'lean'`), statement for statement,
3
+ * that counts every `vdb_load` it makes: how many pool words one `vdbAccessorInit`, `vdbReadValue`, `vdbIsActive` or
4
+ * `vdbSample` reads, for each accessor cache (`'leaf'`, `'lower'`, `'lowerLeaf'`), each init (checked, unchecked)
5
+ * and each grid type. Counts, never timings.
6
+ *
7
+ * It returns the values too (f32, the WGSL's decode; `mix(a, b, t)` as `a + (b - a) * t`, the form SwiftShader
8
+ * evaluates, so the samples equal the GPU's bit for bit there; WGSL allows `a * (1 - t) + b * t` too), so a test holds it against
9
+ * `vdbReadValueF32Cpu` / `vdbSampleTrilinearCpu`: a twin that read the wrong word would return the wrong value.
10
+ *
11
+ * It runs on the grid image alone. The pool-table words an init reads (grid count, the record's flags, type, image
12
+ * offset and index bbox) are counted as loads of named pseudo-words, since their values come from the image here.
13
+ *
14
+ * Tools internal (`src/tools/internal.ts`), not a package export.
15
+ */
16
+ import { vdbHalfToFloat } from "../nanovdb/half.js";
17
+ import { VDBToolsError } from "../errors.js";
18
+ import { indexBBox } from "./march.js";
19
+ const GRID_SIZE = 672;
20
+ const GRID_TYPE_WORD = 636 >>> 2;
21
+ const TYPE = { float: 1, half: 9, fp4: 13, fp8: 14, fp16: 15, fpn: 16 };
22
+ const f = Math.fround;
23
+ /** Pseudo-addresses of the pool-table words (negative: never an image word). */
24
+ const T_COUNT = -1;
25
+ const T_FLAGS = -2;
26
+ const T_TYPE = -3;
27
+ const T_OFFSET = -4;
28
+ const T_BBOX = -10;
29
+ /** The lean reader on one grid image, counting loads. */
30
+ export class LeanReadCounter {
31
+ image;
32
+ cache;
33
+ zero;
34
+ gridType;
35
+ compiledTypes;
36
+ lo;
37
+ hi;
38
+ table = 0;
39
+ loads = 0;
40
+ seen = new Set();
41
+ constructor(image, options = {}) {
42
+ this.image = image;
43
+ this.cache = options.cache ?? "leaf";
44
+ this.zero = (options.outside ?? "background") === "zero";
45
+ this.compiledTypes = options.compiledTypes ?? 1;
46
+ this.gridType = image[GRID_TYPE_WORD];
47
+ if (!Object.values(TYPE).includes(this.gridType)) {
48
+ throw new VDBToolsError("VDB_UNSUPPORTED", `LeanReadCounter: grid type ${this.gridType} is not Float, Half, Fp4, Fp8, Fp16 or FpN.`);
49
+ }
50
+ const { min, max } = indexBBox(image);
51
+ this.lo = [min[0], min[1], min[2]];
52
+ this.hi = [max[0], max[1], max[2]];
53
+ }
54
+ /** Forget the loads counted so far. */
55
+ reset() {
56
+ this.table = 0;
57
+ this.loads = 0;
58
+ this.seen.clear();
59
+ }
60
+ /** Loads since the last `reset()`. */
61
+ get counts() {
62
+ return { table: this.table, image: this.loads, distinct: this.seen.size };
63
+ }
64
+ rec(word) {
65
+ this.table++;
66
+ this.seen.add(word);
67
+ }
68
+ /** `vdb_ln_w`. */
69
+ w(a) {
70
+ this.loads++;
71
+ this.seen.add(a >>> 2);
72
+ return this.image[a >>> 2];
73
+ }
74
+ bit(m, n) {
75
+ return (this.w(m + 4 * (n >>> 5)) >>> (n & 31)) & 1;
76
+ }
77
+ /** `vdb_live(g)`: the grid count and the record's flags. */
78
+ live() {
79
+ this.rec(T_COUNT);
80
+ this.rec(T_FLAGS);
81
+ }
82
+ root = 0;
83
+ /**
84
+ * `vdbAccessorInit(g)` (`'checked'`) or the helper `vdbAccessorInitUnchecked(g)`.
85
+ * Checked: `vdbGridType` (live check, type), the image offset, the root offset (an image word) and, with
86
+ * `outside: 'zero'`, `vdbIndexMin` and `vdbIndexMax` (a live check and 3 words each).
87
+ * Unchecked: the type (only in a module of several types), the image offset, the root offset, the 6 bbox words.
88
+ */
89
+ accessor(init = "checked") {
90
+ if (init === "checked") {
91
+ this.live();
92
+ this.rec(T_TYPE);
93
+ this.rec(T_OFFSET);
94
+ this.root = GRID_SIZE + this.w(GRID_SIZE + 24);
95
+ if (this.zero) {
96
+ for (let side = 0; side < 2; side++) {
97
+ this.live();
98
+ for (let k = 0; k < 3; k++)
99
+ this.rec(T_BBOX - side * 3 - k);
100
+ }
101
+ }
102
+ }
103
+ else {
104
+ if (this.compiledTypes > 1)
105
+ this.rec(T_TYPE);
106
+ this.rec(T_OFFSET);
107
+ this.root = GRID_SIZE + this.w(GRID_SIZE + 24);
108
+ if (this.zero)
109
+ for (let k = 0; k < 6; k++)
110
+ this.rec(T_BBOX - k);
111
+ }
112
+ return { ok: true, lk: [0, 0, 0], la: 0, qk: [0, 0, 0], qa: 0 };
113
+ }
114
+ /** `vdb_ln_lower`: (address, level) with level 1 the lower node, 2 upper tile, 3 root tile, 4 background; then (mask word address, bit). */
115
+ lower(i, j, k) {
116
+ const ux = i >>> 0;
117
+ const uy = j >>> 0;
118
+ const uz = k >>> 0;
119
+ const kl = ((uz >>> 12) | ((uy >>> 12) << 21)) >>> 0;
120
+ const kh = ((uy >>> 23) | ((ux >>> 12) << 10)) >>> 0;
121
+ const r = this.root;
122
+ const n = this.w(r + 24);
123
+ for (let t = 0; t < n; t++) {
124
+ const e = r + 64 + t * 32;
125
+ if (this.w(e) !== kl || this.w(e + 4) !== kh)
126
+ continue;
127
+ const c = this.w(e + 8);
128
+ if (c === 0 && this.w(e + 12) === 0)
129
+ return [e + 20, 3, e + 16, 0];
130
+ const p = r + c;
131
+ const un = (((ux & 4095) >>> 7) << 10) | (((uy & 4095) >>> 7) << 5) | ((uz & 4095) >>> 7);
132
+ const ue = p + 8256 + 8 * un;
133
+ if (this.bit(p + 4128, un) === 0)
134
+ return [ue, 2, p + 32, un];
135
+ return [p + this.w(ue), 1, 0, 0];
136
+ }
137
+ return [r + 28, 4, 0, 0];
138
+ }
139
+ /** `vdb_ln_down`: the lower node's child lookup: (address, level 0 leaf / 1 lower tile, mask word address, bit). */
140
+ down(q, i, j, k) {
141
+ const ln = (((i & 127) >>> 3) << 8) | (((j & 127) >>> 3) << 4) | ((k & 127) >>> 3);
142
+ const fe = q + 1088 + 8 * ln;
143
+ if (this.bit(q + 544, ln) === 0)
144
+ return [fe, 1, q + 32, ln];
145
+ const l = q + this.w(fe);
146
+ return [l, 0, l + 16, ((i & 7) << 6) | ((j & 7) << 3) | (k & 7)];
147
+ }
148
+ /** `vdb_ln_find`: the whole descent. */
149
+ find(i, j, k) {
150
+ const lw = this.lower(i, j, k);
151
+ if (lw[1] !== 1)
152
+ return lw;
153
+ return this.down(lw[0], i, j, k);
154
+ }
155
+ f32(a) {
156
+ const u = this.w(a);
157
+ return new Float32Array(new Uint32Array([u]).buffer)[0];
158
+ }
159
+ /** `vdb_ln_tile`: a tile or background slot. */
160
+ tile(a) {
161
+ if (this.gridType === TYPE.half)
162
+ return vdbHalfToFloat((this.w(a) >>> ((a & 2) << 3)) & 0xffff);
163
+ return this.f32(a);
164
+ }
165
+ /** `vdb_ln_leaf`: voxel `n` of the leaf at `l`. */
166
+ leaf(l, n) {
167
+ const t = this.gridType;
168
+ if (t === TYPE.float)
169
+ return this.f32(l + 96 + 4 * n);
170
+ if (t === TYPE.half)
171
+ return vdbHalfToFloat((this.w(l + 96 + 2 * n) >>> ((n & 1) << 4)) & 0xffff);
172
+ const lb = t === TYPE.fp4 ? 2 : t === TYPE.fp8 ? 3 : t === TYPE.fp16 ? 4 : this.w(l + 12) >>> 29;
173
+ const pw = 5 - lb;
174
+ const bits = 1 << lb;
175
+ const mask = bits === 32 ? 0xffffffff : (1 << bits) - 1;
176
+ const c = ((this.w(l + 96 + ((n >>> pw) << 2)) >>> ((n & ((1 << pw) - 1)) << lb)) & mask) >>> 0;
177
+ const quantum = this.f32(l + 84);
178
+ const minimum = this.f32(l + 80);
179
+ return f(f(f(c) * quantum) + minimum);
180
+ }
181
+ differs(key, i, j, k, m) {
182
+ return (i & m) !== key[0] || (j & m) !== key[1] || (k & m) !== key[2];
183
+ }
184
+ /** `vdbReadValue(&acc, ijk)`. */
185
+ readValue(acc, ijk) {
186
+ if (!acc.ok)
187
+ return 0;
188
+ const [i, j, k] = ijk;
189
+ const n = ((i & 7) << 6) | ((j & 7) << 3) | (k & 7);
190
+ if (this.cache === "leaf") {
191
+ if (acc.la === 0 || this.differs(acc.lk, i, j, k, -8)) {
192
+ const fd = this.find(i, j, k);
193
+ if (fd[1] !== 0)
194
+ return this.tile(fd[0]);
195
+ acc.la = fd[0];
196
+ acc.lk = [i & -8, j & -8, k & -8];
197
+ }
198
+ return this.leaf(acc.la, n);
199
+ }
200
+ const both = this.cache === "lowerLeaf";
201
+ if (both && !(acc.la === 0 || this.differs(acc.lk, i, j, k, -8)))
202
+ return this.leaf(acc.la, n);
203
+ // The lower node: the cached one, else a walk from the root.
204
+ let q = both ? acc.qa : acc.la;
205
+ if (q === 0 || this.differs(both ? acc.qk : acc.lk, i, j, k, -128)) {
206
+ const lw = this.lower(i, j, k);
207
+ if (lw[1] !== 1)
208
+ return this.tile(lw[0]);
209
+ q = lw[0];
210
+ const key = [i & -128, j & -128, k & -128];
211
+ if (both) {
212
+ acc.qa = q;
213
+ acc.qk = key;
214
+ }
215
+ else {
216
+ acc.la = q;
217
+ acc.lk = key;
218
+ }
219
+ }
220
+ const d = this.down(q, i, j, k);
221
+ if (d[1] !== 0)
222
+ return this.tile(d[0]);
223
+ if (both) {
224
+ acc.la = d[0];
225
+ acc.lk = [i & -8, j & -8, k & -8];
226
+ return this.leaf(acc.la, n);
227
+ }
228
+ return this.leaf(d[0], d[3]);
229
+ }
230
+ /** `vdbIsActive(&acc, ijk)` (no cache: a walk from the root every time). */
231
+ isActive(acc, ijk) {
232
+ if (!acc.ok)
233
+ return false;
234
+ const fd = this.find(ijk[0], ijk[1], ijk[2]);
235
+ return fd[1] < 4 && this.bit(fd[2], fd[3]) !== 0;
236
+ }
237
+ tap(acc, i, j, k) {
238
+ if (this.zero && (i < this.lo[0] || j < this.lo[1] || k < this.lo[2] || i > this.hi[0] || j > this.hi[1] || k > this.hi[2]))
239
+ return 0;
240
+ return this.readValue(acc, [i, j, k]);
241
+ }
242
+ /** `vdbSample(&acc, xyz)`, trilinear (and `vdbSampleFast`, the same function under the lean reader). */
243
+ sample(acc, xyz) {
244
+ const bx = Math.floor(xyz[0]);
245
+ const by = Math.floor(xyz[1]);
246
+ const bz = Math.floor(xyz[2]);
247
+ if (!acc.ok)
248
+ return 0;
249
+ if (this.zero && (bx < this.lo[0] - 1 || by < this.lo[1] - 1 || bz < this.lo[2] - 1 || bx > this.hi[0] || by > this.hi[1] || bz > this.hi[2]))
250
+ return 0;
251
+ const ux = f(xyz[0] - bx);
252
+ const uy = f(xyz[1] - by);
253
+ const uz = f(xyz[2] - bz);
254
+ const mix = (a, b, t) => f(a + f(f(b - a) * t));
255
+ const x00 = mix(this.tap(acc, bx, by, bz), this.tap(acc, bx + 1, by, bz), ux);
256
+ const x10 = mix(this.tap(acc, bx, by + 1, bz), this.tap(acc, bx + 1, by + 1, bz), ux);
257
+ const x01 = mix(this.tap(acc, bx, by, bz + 1), this.tap(acc, bx + 1, by, bz + 1), ux);
258
+ const x11 = mix(this.tap(acc, bx, by + 1, bz + 1), this.tap(acc, bx + 1, by + 1, bz + 1), ux);
259
+ return mix(mix(x00, x10, uy), mix(x01, x11, uy), uz);
260
+ }
261
+ }
262
+ //# sourceMappingURL=lean-reads.js.map