@pmndrs/vdb 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (390) hide show
  1. package/CHANGELOG.md +137 -0
  2. package/LICENSE +21 -0
  3. package/README.md +448 -2
  4. package/THIRD_PARTY_NOTICES.md +147 -0
  5. package/dist/core/compute/atlas.d.ts +94 -0
  6. package/dist/core/compute/atlas.js +98 -0
  7. package/dist/core/compute/atlas.js.map +1 -0
  8. package/dist/core/compute/index.d.ts +13 -0
  9. package/dist/core/compute/index.js +9 -0
  10. package/dist/core/compute/index.js.map +1 -0
  11. package/dist/core/compute/pyramid.d.ts +105 -0
  12. package/dist/core/compute/pyramid.js +455 -0
  13. package/dist/core/compute/pyramid.js.map +1 -0
  14. package/dist/core/compute/shared.d.ts +115 -0
  15. package/dist/core/compute/shared.js +211 -0
  16. package/dist/core/compute/shared.js.map +1 -0
  17. package/dist/core/compute/stats.d.ts +71 -0
  18. package/dist/core/compute/stats.js +188 -0
  19. package/dist/core/compute/stats.js.map +1 -0
  20. package/dist/core/compute/value-transform.d.ts +23 -0
  21. package/dist/core/compute/value-transform.js +58 -0
  22. package/dist/core/compute/value-transform.js.map +1 -0
  23. package/dist/core/errors.d.ts +11 -0
  24. package/dist/core/errors.js +9 -0
  25. package/dist/core/errors.js.map +1 -0
  26. package/dist/core/index.d.ts +30 -0
  27. package/dist/core/index.js +27 -0
  28. package/dist/core/index.js.map +1 -0
  29. package/dist/core/internal.d.ts +15 -0
  30. package/dist/core/internal.js +15 -0
  31. package/dist/core/internal.js.map +1 -0
  32. package/dist/core/pool/affine.d.ts +34 -0
  33. package/dist/core/pool/affine.js +100 -0
  34. package/dist/core/pool/affine.js.map +1 -0
  35. package/dist/core/pool/allocator.d.ts +32 -0
  36. package/dist/core/pool/allocator.js +81 -0
  37. package/dist/core/pool/allocator.js.map +1 -0
  38. package/dist/core/pool/image-header.d.ts +82 -0
  39. package/dist/core/pool/image-header.js +175 -0
  40. package/dist/core/pool/image-header.js.map +1 -0
  41. package/dist/core/pool/layout.d.ts +164 -0
  42. package/dist/core/pool/layout.js +267 -0
  43. package/dist/core/pool/layout.js.map +1 -0
  44. package/dist/core/pool/limits.d.ts +40 -0
  45. package/dist/core/pool/limits.js +79 -0
  46. package/dist/core/pool/limits.js.map +1 -0
  47. package/dist/core/pool/pool.d.ts +279 -0
  48. package/dist/core/pool/pool.js +953 -0
  49. package/dist/core/pool/pool.js.map +1 -0
  50. package/dist/core/source/dense.d.ts +19 -0
  51. package/dist/core/source/dense.js +287 -0
  52. package/dist/core/source/dense.js.map +1 -0
  53. package/dist/core/source/types.d.ts +63 -0
  54. package/dist/core/source/types.js +9 -0
  55. package/dist/core/source/types.js.map +1 -0
  56. package/dist/core/types.d.ts +28 -0
  57. package/dist/core/types.js +28 -0
  58. package/dist/core/types.js.map +1 -0
  59. package/dist/core/wgsl/api.d.ts +41 -0
  60. package/dist/core/wgsl/api.js +463 -0
  61. package/dist/core/wgsl/api.js.map +1 -0
  62. package/dist/core/wgsl/generate.d.ts +82 -0
  63. package/dist/core/wgsl/generate.js +505 -0
  64. package/dist/core/wgsl/generate.js.map +1 -0
  65. package/dist/core/wgsl/level-set.d.ts +54 -0
  66. package/dist/core/wgsl/level-set.js +194 -0
  67. package/dist/core/wgsl/level-set.js.map +1 -0
  68. package/dist/core/wgsl/pnanovdb.chunks.generated.d.ts +14 -0
  69. package/dist/core/wgsl/pnanovdb.chunks.generated.js +330 -0
  70. package/dist/core/wgsl/pnanovdb.chunks.generated.js.map +1 -0
  71. package/dist/core/wgsl/reserved.d.ts +9 -0
  72. package/dist/core/wgsl/reserved.js +26 -0
  73. package/dist/core/wgsl/reserved.js.map +1 -0
  74. package/dist/core/wgsl/types.d.ts +104 -0
  75. package/dist/core/wgsl/types.js +2 -0
  76. package/dist/core/wgsl/types.js.map +1 -0
  77. package/dist/three/coarse-first.d.ts +162 -0
  78. package/dist/three/coarse-first.js +187 -0
  79. package/dist/three/coarse-first.js.map +1 -0
  80. package/dist/three/compute.d.ts +63 -0
  81. package/dist/three/compute.js +56 -0
  82. package/dist/three/compute.js.map +1 -0
  83. package/dist/three/device.d.ts +59 -0
  84. package/dist/three/device.js +59 -0
  85. package/dist/three/device.js.map +1 -0
  86. package/dist/three/frame/blackbody.d.ts +42 -0
  87. package/dist/three/frame/blackbody.js +74 -0
  88. package/dist/three/frame/blackbody.js.map +1 -0
  89. package/dist/three/frame/chunks.d.ts +157 -0
  90. package/dist/three/frame/chunks.js +559 -0
  91. package/dist/three/frame/chunks.js.map +1 -0
  92. package/dist/three/frame/density-material.d.ts +53 -0
  93. package/dist/three/frame/density-material.js +353 -0
  94. package/dist/three/frame/density-material.js.map +1 -0
  95. package/dist/three/frame/emission-light.d.ts +167 -0
  96. package/dist/three/frame/emission-light.js +655 -0
  97. package/dist/three/frame/emission-light.js.map +1 -0
  98. package/dist/three/frame/environment-grid-material.d.ts +21 -0
  99. package/dist/three/frame/environment-grid-material.js +184 -0
  100. package/dist/three/frame/environment-grid-material.js.map +1 -0
  101. package/dist/three/frame/environment-material.d.ts +22 -0
  102. package/dist/three/frame/environment-material.js +87 -0
  103. package/dist/three/frame/environment-material.js.map +1 -0
  104. package/dist/three/frame/grid-mip-material.d.ts +12 -0
  105. package/dist/three/frame/grid-mip-material.js +61 -0
  106. package/dist/three/frame/grid-mip-material.js.map +1 -0
  107. package/dist/three/frame/index.d.ts +39 -0
  108. package/dist/three/frame/index.js +35 -0
  109. package/dist/three/frame/index.js.map +1 -0
  110. package/dist/three/frame/inject-material.d.ts +56 -0
  111. package/dist/three/frame/inject-material.js +424 -0
  112. package/dist/three/frame/inject-material.js.map +1 -0
  113. package/dist/three/frame/integrate-material.d.ts +26 -0
  114. package/dist/three/frame/integrate-material.js +198 -0
  115. package/dist/three/frame/integrate-material.js.map +1 -0
  116. package/dist/three/frame/layout.d.ts +34 -0
  117. package/dist/three/frame/layout.js +48 -0
  118. package/dist/three/frame/layout.js.map +1 -0
  119. package/dist/three/frame/lighting-material.d.ts +41 -0
  120. package/dist/three/frame/lighting-material.js +257 -0
  121. package/dist/three/frame/lighting-material.js.map +1 -0
  122. package/dist/three/frame/lights.d.ts +11 -0
  123. package/dist/three/frame/lights.js +16 -0
  124. package/dist/three/frame/lights.js.map +1 -0
  125. package/dist/three/frame/medium.d.ts +21 -0
  126. package/dist/three/frame/medium.js +29 -0
  127. package/dist/three/frame/medium.js.map +1 -0
  128. package/dist/three/frame/neural.d.ts +14 -0
  129. package/dist/three/frame/neural.js +105 -0
  130. package/dist/three/frame/neural.js.map +1 -0
  131. package/dist/three/frame/phase.d.ts +44 -0
  132. package/dist/three/frame/phase.js +80 -0
  133. package/dist/three/frame/phase.js.map +1 -0
  134. package/dist/three/frame/renderer.d.ts +493 -0
  135. package/dist/three/frame/renderer.js +1498 -0
  136. package/dist/three/frame/renderer.js.map +1 -0
  137. package/dist/three/frame/shadow-density-material.d.ts +30 -0
  138. package/dist/three/frame/shadow-density-material.js +123 -0
  139. package/dist/three/frame/shadow-density-material.js.map +1 -0
  140. package/dist/three/frame/spectrum.d.ts +18 -0
  141. package/dist/three/frame/spectrum.js +36 -0
  142. package/dist/three/frame/spectrum.js.map +1 -0
  143. package/dist/three/frame/temporal-material.d.ts +29 -0
  144. package/dist/three/frame/temporal-material.js +152 -0
  145. package/dist/three/frame/temporal-material.js.map +1 -0
  146. package/dist/three/frame/three-internals.d.ts +65 -0
  147. package/dist/three/frame/three-internals.js +150 -0
  148. package/dist/three/frame/three-internals.js.map +1 -0
  149. package/dist/three/frame/transmittance-material.d.ts +31 -0
  150. package/dist/three/frame/transmittance-material.js +315 -0
  151. package/dist/three/frame/transmittance-material.js.map +1 -0
  152. package/dist/three/frame/view.d.ts +103 -0
  153. package/dist/three/frame/view.js +296 -0
  154. package/dist/three/frame/view.js.map +1 -0
  155. package/dist/three/frame/volume-shadow-material.d.ts +36 -0
  156. package/dist/three/frame/volume-shadow-material.js +128 -0
  157. package/dist/three/frame/volume-shadow-material.js.map +1 -0
  158. package/dist/three/frame/volume-shadows.d.ts +153 -0
  159. package/dist/three/frame/volume-shadows.js +756 -0
  160. package/dist/three/frame/volume-shadows.js.map +1 -0
  161. package/dist/three/frame/volume.d.ts +172 -0
  162. package/dist/three/frame/volume.js +256 -0
  163. package/dist/three/frame/volume.js.map +1 -0
  164. package/dist/three/grid-node.d.ts +196 -0
  165. package/dist/three/grid-node.js +510 -0
  166. package/dist/three/grid-node.js.map +1 -0
  167. package/dist/three/index.d.ts +43 -0
  168. package/dist/three/index.js +49 -0
  169. package/dist/three/index.js.map +1 -0
  170. package/dist/three/internal.d.ts +14 -0
  171. package/dist/three/internal.js +14 -0
  172. package/dist/three/internal.js.map +1 -0
  173. package/dist/three/level-set-material.d.ts +112 -0
  174. package/dist/three/level-set-material.js +204 -0
  175. package/dist/three/level-set-material.js.map +1 -0
  176. package/dist/three/material.d.ts +194 -0
  177. package/dist/three/material.js +359 -0
  178. package/dist/three/material.js.map +1 -0
  179. package/dist/three/points.d.ts +84 -0
  180. package/dist/three/points.js +130 -0
  181. package/dist/three/points.js.map +1 -0
  182. package/dist/three/sequence.d.ts +317 -0
  183. package/dist/three/sequence.js +526 -0
  184. package/dist/three/sequence.js.map +1 -0
  185. package/dist/three/sparse-source.d.ts +233 -0
  186. package/dist/three/sparse-source.js +876 -0
  187. package/dist/three/sparse-source.js.map +1 -0
  188. package/dist/three/volume-source.d.ts +167 -0
  189. package/dist/three/volume-source.js +353 -0
  190. package/dist/three/volume-source.js.map +1 -0
  191. package/dist/tools/cpu/compute.d.ts +97 -0
  192. package/dist/tools/cpu/compute.js +218 -0
  193. package/dist/tools/cpu/compute.js.map +1 -0
  194. package/dist/tools/cpu/level-set.d.ts +72 -0
  195. package/dist/tools/cpu/level-set.js +261 -0
  196. package/dist/tools/cpu/level-set.js.map +1 -0
  197. package/dist/tools/cpu/march.d.ts +206 -0
  198. package/dist/tools/cpu/march.js +575 -0
  199. package/dist/tools/cpu/march.js.map +1 -0
  200. package/dist/tools/cpu/probe-coords.d.ts +70 -0
  201. package/dist/tools/cpu/probe-coords.js +116 -0
  202. package/dist/tools/cpu/probe-coords.js.map +1 -0
  203. package/dist/tools/cpu/read-value.d.ts +31 -0
  204. package/dist/tools/cpu/read-value.js +336 -0
  205. package/dist/tools/cpu/read-value.js.map +1 -0
  206. package/dist/tools/cpu/sample-trilinear.d.ts +30 -0
  207. package/dist/tools/cpu/sample-trilinear.js +156 -0
  208. package/dist/tools/cpu/sample-trilinear.js.map +1 -0
  209. package/dist/tools/cpu/stride-tables.d.ts +56 -0
  210. package/dist/tools/cpu/stride-tables.generated.d.ts +1058 -0
  211. package/dist/tools/cpu/stride-tables.generated.js +1266 -0
  212. package/dist/tools/cpu/stride-tables.generated.js.map +1 -0
  213. package/dist/tools/cpu/stride-tables.js +78 -0
  214. package/dist/tools/cpu/stride-tables.js.map +1 -0
  215. package/dist/tools/errors.d.ts +57 -0
  216. package/dist/tools/errors.js +58 -0
  217. package/dist/tools/errors.js.map +1 -0
  218. package/dist/tools/frame/blackbody.d.ts +42 -0
  219. package/dist/tools/frame/blackbody.js +116 -0
  220. package/dist/tools/frame/blackbody.js.map +1 -0
  221. package/dist/tools/frame/emission.d.ts +128 -0
  222. package/dist/tools/frame/emission.js +282 -0
  223. package/dist/tools/frame/emission.js.map +1 -0
  224. package/dist/tools/frame/environment.d.ts +105 -0
  225. package/dist/tools/frame/environment.js +268 -0
  226. package/dist/tools/frame/environment.js.map +1 -0
  227. package/dist/tools/frame/grid.d.ts +302 -0
  228. package/dist/tools/frame/grid.js +703 -0
  229. package/dist/tools/frame/grid.js.map +1 -0
  230. package/dist/tools/frame/index.d.ts +136 -0
  231. package/dist/tools/frame/index.js +348 -0
  232. package/dist/tools/frame/index.js.map +1 -0
  233. package/dist/tools/frame/medium.d.ts +61 -0
  234. package/dist/tools/frame/medium.js +99 -0
  235. package/dist/tools/frame/medium.js.map +1 -0
  236. package/dist/tools/frame/mie-table.d.ts +6 -0
  237. package/dist/tools/frame/mie-table.js +16 -0
  238. package/dist/tools/frame/mie-table.js.map +1 -0
  239. package/dist/tools/frame/mie.d.ts +54 -0
  240. package/dist/tools/frame/mie.js +176 -0
  241. package/dist/tools/frame/mie.js.map +1 -0
  242. package/dist/tools/frame/neural-weights.d.ts +9 -0
  243. package/dist/tools/frame/neural-weights.js +245 -0
  244. package/dist/tools/frame/neural-weights.js.map +1 -0
  245. package/dist/tools/frame/neural.d.ts +80 -0
  246. package/dist/tools/frame/neural.js +150 -0
  247. package/dist/tools/frame/neural.js.map +1 -0
  248. package/dist/tools/frame/pyramid-layout.d.ts +38 -0
  249. package/dist/tools/frame/pyramid-layout.js +53 -0
  250. package/dist/tools/frame/pyramid-layout.js.map +1 -0
  251. package/dist/tools/frame/shadows.d.ts +80 -0
  252. package/dist/tools/frame/shadows.js +182 -0
  253. package/dist/tools/frame/shadows.js.map +1 -0
  254. package/dist/tools/frame/sparse.d.ts +65 -0
  255. package/dist/tools/frame/sparse.js +191 -0
  256. package/dist/tools/frame/sparse.js.map +1 -0
  257. package/dist/tools/frame/spectral.d.ts +203 -0
  258. package/dist/tools/frame/spectral.js +550 -0
  259. package/dist/tools/frame/spectral.js.map +1 -0
  260. package/dist/tools/index.d.ts +106 -0
  261. package/dist/tools/index.js +88 -0
  262. package/dist/tools/index.js.map +1 -0
  263. package/dist/tools/internal.d.ts +46 -0
  264. package/dist/tools/internal.js +31 -0
  265. package/dist/tools/internal.js.map +1 -0
  266. package/dist/tools/nanovdb/build-from-vdb.d.ts +50 -0
  267. package/dist/tools/nanovdb/build-from-vdb.js +92 -0
  268. package/dist/tools/nanovdb/build-from-vdb.js.map +1 -0
  269. package/dist/tools/nanovdb/bytes.d.ts +220 -0
  270. package/dist/tools/nanovdb/bytes.js +345 -0
  271. package/dist/tools/nanovdb/bytes.js.map +1 -0
  272. package/dist/tools/nanovdb/coarse-first.d.ts +62 -0
  273. package/dist/tools/nanovdb/coarse-first.js +86 -0
  274. package/dist/tools/nanovdb/coarse-first.js.map +1 -0
  275. package/dist/tools/nanovdb/index.d.ts +32 -0
  276. package/dist/tools/nanovdb/index.js +24 -0
  277. package/dist/tools/nanovdb/index.js.map +1 -0
  278. package/dist/tools/nanovdb/inspect.d.ts +24 -0
  279. package/dist/tools/nanovdb/inspect.js +63 -0
  280. package/dist/tools/nanovdb/inspect.js.map +1 -0
  281. package/dist/tools/nanovdb/leaf-codec.d.ts +85 -0
  282. package/dist/tools/nanovdb/leaf-codec.js +320 -0
  283. package/dist/tools/nanovdb/leaf-codec.js.map +1 -0
  284. package/dist/tools/nanovdb/quantize.d.ts +43 -0
  285. package/dist/tools/nanovdb/quantize.js +277 -0
  286. package/dist/tools/nanovdb/quantize.js.map +1 -0
  287. package/dist/tools/nanovdb/resample.d.ts +160 -0
  288. package/dist/tools/nanovdb/resample.js +679 -0
  289. package/dist/tools/nanovdb/resample.js.map +1 -0
  290. package/dist/tools/nanovdb/serialize.d.ts +145 -0
  291. package/dist/tools/nanovdb/serialize.js +395 -0
  292. package/dist/tools/nanovdb/serialize.js.map +1 -0
  293. package/dist/tools/nanovdb/stats.d.ts +58 -0
  294. package/dist/tools/nanovdb/stats.js +149 -0
  295. package/dist/tools/nanovdb/stats.js.map +1 -0
  296. package/dist/tools/nanovdb/transform.d.ts +26 -0
  297. package/dist/tools/nanovdb/transform.js +91 -0
  298. package/dist/tools/nanovdb/transform.js.map +1 -0
  299. package/dist/tools/nanovdb/tree.d.ts +175 -0
  300. package/dist/tools/nanovdb/tree.js +518 -0
  301. package/dist/tools/nanovdb/tree.js.map +1 -0
  302. package/dist/tools/nanovdb/write-nvdb.d.ts +39 -0
  303. package/dist/tools/nanovdb/write-nvdb.js +210 -0
  304. package/dist/tools/nanovdb/write-nvdb.js.map +1 -0
  305. package/dist/tools/nvdb-file.d.ts +195 -0
  306. package/dist/tools/nvdb-file.js +606 -0
  307. package/dist/tools/nvdb-file.js.map +1 -0
  308. package/dist/tools/nvdb-stream.d.ts +138 -0
  309. package/dist/tools/nvdb-stream.js +365 -0
  310. package/dist/tools/nvdb-stream.js.map +1 -0
  311. package/dist/tools/vdb/bit-utils.d.ts +20 -0
  312. package/dist/tools/vdb/bit-utils.js +42 -0
  313. package/dist/tools/vdb/bit-utils.js.map +1 -0
  314. package/dist/tools/vdb/blosc.d.ts +56 -0
  315. package/dist/tools/vdb/blosc.js +231 -0
  316. package/dist/tools/vdb/blosc.js.map +1 -0
  317. package/dist/tools/vdb/byte-reader.d.ts +40 -0
  318. package/dist/tools/vdb/byte-reader.js +139 -0
  319. package/dist/tools/vdb/byte-reader.js.map +1 -0
  320. package/dist/tools/vdb/compression.d.ts +73 -0
  321. package/dist/tools/vdb/compression.js +249 -0
  322. package/dist/tools/vdb/compression.js.map +1 -0
  323. package/dist/tools/vdb/errors.d.ts +10 -0
  324. package/dist/tools/vdb/errors.js +11 -0
  325. package/dist/tools/vdb/errors.js.map +1 -0
  326. package/dist/tools/vdb/grid.d.ts +37 -0
  327. package/dist/tools/vdb/grid.js +147 -0
  328. package/dist/tools/vdb/grid.js.map +1 -0
  329. package/dist/tools/vdb/half-float.d.ts +9 -0
  330. package/dist/tools/vdb/half-float.js +24 -0
  331. package/dist/tools/vdb/half-float.js.map +1 -0
  332. package/dist/tools/vdb/index.d.ts +3 -0
  333. package/dist/tools/vdb/index.js +3 -0
  334. package/dist/tools/vdb/index.js.map +1 -0
  335. package/dist/tools/vdb/inflate.d.ts +24 -0
  336. package/dist/tools/vdb/inflate.js +334 -0
  337. package/dist/tools/vdb/inflate.js.map +1 -0
  338. package/dist/tools/vdb/metadata.d.ts +17 -0
  339. package/dist/tools/vdb/metadata.js +72 -0
  340. package/dist/tools/vdb/metadata.js.map +1 -0
  341. package/dist/tools/vdb/parse.d.ts +25 -0
  342. package/dist/tools/vdb/parse.js +171 -0
  343. package/dist/tools/vdb/parse.js.map +1 -0
  344. package/dist/tools/vdb/point-render-data.d.ts +31 -0
  345. package/dist/tools/vdb/point-render-data.js +57 -0
  346. package/dist/tools/vdb/point-render-data.js.map +1 -0
  347. package/dist/tools/vdb/points.d.ts +160 -0
  348. package/dist/tools/vdb/points.js +794 -0
  349. package/dist/tools/vdb/points.js.map +1 -0
  350. package/dist/tools/vdb/transform.d.ts +23 -0
  351. package/dist/tools/vdb/transform.js +54 -0
  352. package/dist/tools/vdb/transform.js.map +1 -0
  353. package/dist/tools/vdb/tree.d.ts +111 -0
  354. package/dist/tools/vdb/tree.js +228 -0
  355. package/dist/tools/vdb/tree.js.map +1 -0
  356. package/dist/tools/vdb/types.d.ts +138 -0
  357. package/dist/tools/vdb/types.js +3 -0
  358. package/dist/tools/vdb/types.js.map +1 -0
  359. package/dist/tools/wvdb/bake.d.ts +116 -0
  360. package/dist/tools/wvdb/bake.js +311 -0
  361. package/dist/tools/wvdb/bake.js.map +1 -0
  362. package/dist/tools/wvdb/dense.d.ts +112 -0
  363. package/dist/tools/wvdb/dense.js +309 -0
  364. package/dist/tools/wvdb/dense.js.map +1 -0
  365. package/dist/tools/wvdb/format.d.ts +161 -0
  366. package/dist/tools/wvdb/format.js +303 -0
  367. package/dist/tools/wvdb/format.js.map +1 -0
  368. package/dist/tools/wvdb/index.d.ts +13 -0
  369. package/dist/tools/wvdb/index.js +14 -0
  370. package/dist/tools/wvdb/index.js.map +1 -0
  371. package/dist/tools/wvdb/level-set.d.ts +48 -0
  372. package/dist/tools/wvdb/level-set.js +153 -0
  373. package/dist/tools/wvdb/level-set.js.map +1 -0
  374. package/dist/tools/wvdb/nanovdb.d.ts +54 -0
  375. package/dist/tools/wvdb/nanovdb.js +60 -0
  376. package/dist/tools/wvdb/nanovdb.js.map +1 -0
  377. package/dist/tools/wvdb/read.d.ts +260 -0
  378. package/dist/tools/wvdb/read.js +743 -0
  379. package/dist/tools/wvdb/read.js.map +1 -0
  380. package/dist/tools/wvdb/sha256.d.ts +7 -0
  381. package/dist/tools/wvdb/sha256.js +76 -0
  382. package/dist/tools/wvdb/sha256.js.map +1 -0
  383. package/dist/tools/wvdb/write.d.ts +127 -0
  384. package/dist/tools/wvdb/write.js +396 -0
  385. package/dist/tools/wvdb/write.js.map +1 -0
  386. package/package.json +82 -4
  387. package/vendor/LICENSE +201 -0
  388. package/vendor/NOTICE +19 -0
  389. package/vendor/VENDOR.md +85 -0
  390. package/vendor/pnanovdb.wgsl +1539 -0
@@ -0,0 +1,575 @@
1
+ /**
2
+ * CPU twins (D11) of the `march` WGSL profile (docs/dev/design/K1-core.md §3.2,
3
+ * task K1.4b): the vendored HDDA (`vdbHddaInit/Update/Step`), the node size at
4
+ * a voxel (`vdbGetDim`), node statistics (the fork's
5
+ * `{root,upper,lower,leaf}_get_{min,max,ave,stddev}_float`, with the K1.4b Fp
6
+ * leaf-stats fix), `vdbNodeMax`, `vdbRayClip`, and `hddaWalk`, the canonical
7
+ * walk the GPU probe kernel runs with the same calls. Also the opt-in helpers
8
+ * (K1.7a): `vdbCellBoundTrilinear`, `vdbHddaCellEnd`, `vdbRayClipSupport`.
9
+ *
10
+ * Float arithmetic: every f32 operation of the WGSL is rounded here with
11
+ * `Math.fround`, in the WGSL's evaluation order. GPUs may fuse a multiply-add
12
+ * or use a less exact division (WGSL allows 2.5 ULP), so GPU parity compares
13
+ * `t` with a tolerance, not bit for bit.
14
+ *
15
+ * What the node stats guarantee (NanoVDB `tools/GridStats.h`): a node's
16
+ * min/max/ave/stddev cover the ACTIVE voxels and ACTIVE tiles of its subtree.
17
+ * They say nothing about inactive voxels, inactive tiles or the background.
18
+ * A trilinear sample at `p` blends voxels `floor(p)` and `floor(p) + 1`, so a
19
+ * sample inside a leaf's cell can read a neighbouring leaf, a tile, or an
20
+ * inactive voxel: the leaf's max does not bound it. The bound for a sample is
21
+ * the max over its 2x2x2 support of each tap's own bound (leaf max for a leaf
22
+ * voxel, the value for a tile or the background), and that is a bound only if
23
+ * every inactive leaf voxel is <= its leaf's max. `test/tools/cpu-march.test.ts`
24
+ * checks exactly these statements per fixture.
25
+ *
26
+ * Fp leaf stats (NanoVDB.h `LeafFnBase`, OpenVDB a532de55): uint16 codes at
27
+ * leaf bytes 88/90/92/94; min/max/ave = code * quantum + minimum, stddev =
28
+ * code * quantum, with the leaf's own mMinimum (byte 80) and mQuantum (84).
29
+ */
30
+ import { VDBToolsError } from "../errors.js";
31
+ import { defineBigInt, defineNumber, gridTypeConstantsForId, gridTypeIds } from "./stride-tables.js";
32
+ const f = Math.fround;
33
+ const GRID_OFF_MAGIC = defineNumber("PNANOVDB_GRID_OFF_MAGIC");
34
+ const GRID_OFF_FLAGS = defineNumber("PNANOVDB_GRID_OFF_FLAGS");
35
+ const GRID_OFF_GRID_TYPE = defineNumber("PNANOVDB_GRID_OFF_GRID_TYPE");
36
+ const GRID_SIZE = defineNumber("PNANOVDB_GRID_SIZE");
37
+ const MAGIC_GRID = defineBigInt("PNANOVDB_MAGIC_GRID");
38
+ const TREE_OFF_NODE_OFFSET_ROOT = defineNumber("PNANOVDB_TREE_OFF_NODE_OFFSET_ROOT");
39
+ const ROOT_OFF_BBOX_MIN = defineNumber("PNANOVDB_ROOT_OFF_BBOX_MIN");
40
+ const ROOT_OFF_BBOX_MAX = defineNumber("PNANOVDB_ROOT_OFF_BBOX_MAX");
41
+ const ROOT_OFF_TABLE_SIZE = defineNumber("PNANOVDB_ROOT_OFF_TABLE_SIZE");
42
+ const ROOT_TILE_OFF_KEY = defineNumber("PNANOVDB_ROOT_TILE_OFF_KEY");
43
+ const ROOT_TILE_OFF_CHILD = defineNumber("PNANOVDB_ROOT_TILE_OFF_CHILD");
44
+ const ROOT_TILE_OFF_STATE = defineNumber("PNANOVDB_ROOT_TILE_OFF_STATE");
45
+ const UPPER_OFF_VALUE_MASK = defineNumber("PNANOVDB_UPPER_OFF_VALUE_MASK");
46
+ const UPPER_OFF_CHILD_MASK = defineNumber("PNANOVDB_UPPER_OFF_CHILD_MASK");
47
+ const LOWER_OFF_VALUE_MASK = defineNumber("PNANOVDB_LOWER_OFF_VALUE_MASK");
48
+ const LOWER_OFF_CHILD_MASK = defineNumber("PNANOVDB_LOWER_OFF_CHILD_MASK");
49
+ const LEAF_OFF_VALUE_MASK = defineNumber("PNANOVDB_LEAF_OFF_VALUE_MASK");
50
+ const LEAF_TABLE_NEG_OFF_BBOX_DIF_AND_FLAGS = defineNumber("PNANOVDB_LEAF_TABLE_NEG_OFF_BBOX_DIF_AND_FLAGS");
51
+ const LEAF_TABLE_NEG_OFF_MINIMUM = defineNumber("PNANOVDB_LEAF_TABLE_NEG_OFF_MINIMUM");
52
+ const LEAF_TABLE_NEG_OFF_QUANTUM = defineNumber("PNANOVDB_LEAF_TABLE_NEG_OFF_QUANTUM");
53
+ /** PNANOVDB_GRID_FLAGS_HAS_MIN_MAX (1 << 2); not in the extracted defines. */
54
+ const GRID_FLAGS_HAS_MIN_MAX = 4;
55
+ /** PNANOVDB_HDDA_FLOAT_MAX. */
56
+ const HDDA_FLOAT_MAX = f(1e38);
57
+ const FORWARD_SCALE = f(0.999999);
58
+ const FORWARD_BIAS = f(1.0e-6);
59
+ const FP_TYPES = new Set([gridTypeIds.FP4, gridTypeIds.FP8, gridTypeIds.FP16, gridTypeIds.FPN]);
60
+ const SUPPORTED_TYPES = new Set([gridTypeIds.FLOAT, ...FP_TYPES]);
61
+ /** Per-image header cache, keyed by the array: images are treated as immutable once read. */
62
+ const grids = new WeakMap();
63
+ function u32(words, address) {
64
+ return words[address >>> 2];
65
+ }
66
+ function grid(words) {
67
+ let g = grids.get(words);
68
+ if (g)
69
+ return g;
70
+ const magic = (BigInt(u32(words, GRID_OFF_MAGIC + 4)) << 32n) | BigInt(u32(words, GRID_OFF_MAGIC));
71
+ if (magic !== MAGIC_GRID)
72
+ throw new VDBToolsError("VDB_BAD_IMAGE", "march: gridWords does not start with a NanoVDB GridData block");
73
+ const gridType = u32(words, GRID_OFF_GRID_TYPE);
74
+ if (!SUPPORTED_TYPES.has(gridType))
75
+ throw new VDBToolsError("VDB_UNSUPPORTED_GRID_TYPE", `march: grid type ${gridType} is not Float/Fp4/Fp8/Fp16/FpN`);
76
+ const root = GRID_SIZE + u32(words, GRID_SIZE + TREE_OFF_NODE_OFFSET_ROOT);
77
+ g = {
78
+ words,
79
+ f32: new Float32Array(words.buffer, words.byteOffset, words.length),
80
+ gridType,
81
+ gt: gridTypeConstantsForId(gridType),
82
+ fp: FP_TYPES.has(gridType),
83
+ hasStats: (u32(words, GRID_OFF_FLAGS) & GRID_FLAGS_HAS_MIN_MAX) !== 0,
84
+ root,
85
+ };
86
+ grids.set(words, g);
87
+ return g;
88
+ }
89
+ function readF32(g, address) {
90
+ return g.f32[address >>> 2];
91
+ }
92
+ /** pnanovdb_read_uint16 (fork, K1.4b): the u16 at a 2-byte-aligned address. */
93
+ function readU16(g, address) {
94
+ return (u32(g.words, address & ~3) >>> ((address & 2) << 3)) & 0xffff;
95
+ }
96
+ function maskBit(g, base, n) {
97
+ return ((u32(g.words, base + 4 * (n >>> 5)) >>> (n & 31)) & 1) !== 0;
98
+ }
99
+ /** Child offset (low word of the i64; the fork's 32-bit addressing). */
100
+ function childOffset(g, address) {
101
+ return u32(g.words, address) | 0;
102
+ }
103
+ function coordKey(x, y, z) {
104
+ return BigInt(z >>> 12) | (BigInt(y >>> 12) << 21n) | (BigInt(x >>> 12) << 42n);
105
+ }
106
+ function locate(g, [x, y, z]) {
107
+ const gt = g.gt;
108
+ const key = coordKey(x, y, z);
109
+ const count = u32(g.words, g.root + ROOT_OFF_TABLE_SIZE);
110
+ let tile = 0;
111
+ for (let i = 0; i < count; i++) {
112
+ const t = g.root + gt.root_size + i * gt.root_tile_size;
113
+ const k = (BigInt(u32(g.words, t + ROOT_TILE_OFF_KEY + 4)) << 32n) | BigInt(u32(g.words, t + ROOT_TILE_OFF_KEY));
114
+ if (k === key) {
115
+ tile = t;
116
+ break;
117
+ }
118
+ }
119
+ const path = { level: 4, upper: 0, lower: 0, leaf: 0, valueAddress: g.root + gt.root_off_background, active: false };
120
+ if (tile === 0)
121
+ return path;
122
+ const child = childOffset(g, tile + ROOT_TILE_OFF_CHILD);
123
+ if (child === 0 && u32(g.words, tile + ROOT_TILE_OFF_CHILD + 4) === 0) {
124
+ path.level = 3;
125
+ path.valueAddress = tile + gt.root_tile_off_value;
126
+ path.active = u32(g.words, tile + ROOT_TILE_OFF_STATE) !== 0;
127
+ return path;
128
+ }
129
+ path.upper = g.root + child;
130
+ const un = (((x & 4095) >> 7) << 10) + (((y & 4095) >> 7) << 5) + ((z & 4095) >> 7);
131
+ const ut = path.upper + gt.upper_off_table + gt.table_stride * un;
132
+ if (!maskBit(g, path.upper + UPPER_OFF_CHILD_MASK, un)) {
133
+ path.level = 2;
134
+ path.valueAddress = ut;
135
+ path.active = maskBit(g, path.upper + UPPER_OFF_VALUE_MASK, un);
136
+ return path;
137
+ }
138
+ path.lower = path.upper + childOffset(g, ut);
139
+ const ln = (((x & 127) >> 3) << 8) + (((y & 127) >> 3) << 4) + ((z & 127) >> 3);
140
+ const lt = path.lower + gt.lower_off_table + gt.table_stride * ln;
141
+ if (!maskBit(g, path.lower + LOWER_OFF_CHILD_MASK, ln)) {
142
+ path.level = 1;
143
+ path.valueAddress = lt;
144
+ path.active = maskBit(g, path.lower + LOWER_OFF_VALUE_MASK, ln);
145
+ return path;
146
+ }
147
+ path.leaf = path.lower + childOffset(g, lt);
148
+ path.level = 0;
149
+ path.active = maskBit(g, path.leaf + LEAF_OFF_VALUE_MASK, ((x & 7) << 6) + ((y & 7) << 3) + (z & 7));
150
+ return path;
151
+ }
152
+ // ---------------------------------------------------------------------------
153
+ // Node size and statistics
154
+ /**
155
+ * Twin of `vdbGetDim` (vendored `readaccessor_get_dim`): 1 inside a leaf, 8 in
156
+ * a lower-node tile, 128 in an upper-node tile, 4096 in a root tile or the
157
+ * background.
158
+ */
159
+ export function getDim(gridWords, ijk) {
160
+ return DIM_OF_LEVEL[locate(grid(gridWords), ijk).level];
161
+ }
162
+ const DIM_OF_LEVEL = [1, 8, 128, 4096, 4096];
163
+ /** pnanovdb_leaf_fp_get_stat_float: `code * quantum (+ minimum)` in f32. */
164
+ function leafFpStat(g, leaf, address, withMinimum) {
165
+ const table = leaf + g.gt.leaf_off_table; // value_stride_bits is 0 for the Fp types
166
+ const minimum = readF32(g, table - LEAF_TABLE_NEG_OFF_MINIMUM);
167
+ const quantum = readF32(g, table - LEAF_TABLE_NEG_OFF_QUANTUM);
168
+ const scaled = f(readU16(g, address) * quantum);
169
+ return withMinimum ? f(scaled + minimum) : scaled;
170
+ }
171
+ /**
172
+ * Twin of the fork's `{root,upper,lower,leaf}_get_{min,max,ave,stddev}_float`
173
+ * for the node at byte `address` of the image. Root, upper and lower stats are
174
+ * f32; Fp leaf stats are uint16 codes decoded against the leaf's quantization.
175
+ * Meaningful only when the grid has stats (`HAS_MIN_MAX`) and the node has
176
+ * active values.
177
+ */
178
+ export function nodeStats(gridWords, level, address) {
179
+ const g = grid(gridWords);
180
+ const gt = g.gt;
181
+ if (level === 0 && g.fp) {
182
+ return {
183
+ min: leafFpStat(g, address, address + gt.leaf_off_min, true),
184
+ max: leafFpStat(g, address, address + gt.leaf_off_max, true),
185
+ ave: leafFpStat(g, address, address + gt.leaf_off_ave, true),
186
+ stddev: leafFpStat(g, address, address + gt.leaf_off_stddev, false),
187
+ };
188
+ }
189
+ const off = level === 0
190
+ ? [gt.leaf_off_min, gt.leaf_off_max, gt.leaf_off_ave, gt.leaf_off_stddev]
191
+ : level === 1
192
+ ? [gt.lower_off_min, gt.lower_off_max, gt.lower_off_ave, gt.lower_off_stddev]
193
+ : level === 2
194
+ ? [gt.upper_off_min, gt.upper_off_max, gt.upper_off_ave, gt.upper_off_stddev]
195
+ : [gt.root_off_min, gt.root_off_max, gt.root_off_ave, gt.root_off_stddev];
196
+ return {
197
+ min: readF32(g, address + off[0]),
198
+ max: readF32(g, address + off[1]),
199
+ ave: readF32(g, address + off[2]),
200
+ stddev: readF32(g, address + off[3]),
201
+ };
202
+ }
203
+ /** Whether the grid carries node stats (`HAS_MIN_MAX`; pool record flag b1). */
204
+ export function gridHasStats(gridWords) {
205
+ return grid(gridWords).hasStats;
206
+ }
207
+ /** The pool's `valueMax` for this image with no caller bound (`VDBGridPool`): max(root max, background), or +Infinity without stats. */
208
+ export function defaultValueMax(gridWords) {
209
+ const g = grid(gridWords);
210
+ if (!g.hasStats)
211
+ return Infinity;
212
+ return Math.max(readF32(g, g.root + g.gt.root_off_max), readF32(g, g.root + g.gt.root_off_background));
213
+ }
214
+ /**
215
+ * Twin of `vdbNodeMax(acc, ijk, dim)`: a bound for the aligned cell of size
216
+ * `dim` holding `ijk`. With `a = getDim(ijk)`: if `a > 1` and `dim <= a` the
217
+ * cell is one tile and the result is its value (exact). Otherwise it is the
218
+ * max statistic of the smallest node spanning the cell (leaf for `dim <= 8`,
219
+ * lower `<= 128`, upper `<= 4096`, else root), which bounds that node's ACTIVE
220
+ * values only; without stats it is `valueMax` (+Infinity unless the caller
221
+ * gave a bound).
222
+ */
223
+ export function nodeMax(gridWords, ijk, dim, options = {}) {
224
+ const g = grid(gridWords);
225
+ const path = locate(g, ijk);
226
+ const a = DIM_OF_LEVEL[path.level];
227
+ if (a > 1 && dim <= a)
228
+ return readF32(g, path.valueAddress);
229
+ if (!g.hasStats)
230
+ return options.valueMax ?? defaultValueMax(gridWords);
231
+ if (dim <= 8)
232
+ return nodeStats(gridWords, 0, path.leaf).max;
233
+ if (dim <= 128)
234
+ return nodeStats(gridWords, 1, path.lower).max;
235
+ if (dim <= 4096)
236
+ return nodeStats(gridWords, 2, path.upper).max;
237
+ return nodeStats(gridWords, 3, g.root).max;
238
+ }
239
+ /** Twin of `vdbIsActive`. */
240
+ export function isActive(gridWords, ijk) {
241
+ return locate(grid(gridWords), ijk).active;
242
+ }
243
+ /**
244
+ * Twin of `vdbReadValue` (f32 decode in WGSL order; any of Float/Fp4/Fp8/Fp16/FpN).
245
+ *
246
+ * This matches the GPU's evaluation order (f32 arithmetic), so it is the right
247
+ * oracle for GPU parity checks. `readValue` instead returns the exact f64
248
+ * decode; on Fp grids the two can differ by 1 ulp (f32).
249
+ */
250
+ export function vdbReadValueF32(gridWords, ijk) {
251
+ const g = grid(gridWords);
252
+ const path = locate(g, ijk);
253
+ if (path.level !== 0)
254
+ return readF32(g, path.valueAddress);
255
+ const n = ((ijk[0] & 7) << 6) + ((ijk[1] & 7) << 3) + (ijk[2] & 7);
256
+ return leafValue(g, path.leaf, n);
257
+ }
258
+ function leafValue(g, leaf, n) {
259
+ const table = leaf + g.gt.leaf_off_table;
260
+ if (!g.fp)
261
+ return readF32(g, table + ((g.gt.value_stride_bits * n) >> 3));
262
+ let logBits;
263
+ if (g.gridType === gridTypeIds.FP4)
264
+ logBits = 2;
265
+ else if (g.gridType === gridTypeIds.FP8)
266
+ logBits = 3;
267
+ else if (g.gridType === gridTypeIds.FP16)
268
+ logBits = 4;
269
+ else
270
+ logBits = (u32(g.words, table - LEAF_TABLE_NEG_OFF_BBOX_DIF_AND_FLAGS) >>> 24) >>> 5;
271
+ const bits = 1 << logBits;
272
+ const perWordBits = 5 - logBits;
273
+ const minimum = readF32(g, table - LEAF_TABLE_NEG_OFF_MINIMUM);
274
+ const quantum = readF32(g, table - LEAF_TABLE_NEG_OFF_QUANTUM);
275
+ const raw = u32(g.words, table + ((n >> perWordBits) << 2));
276
+ const code = (raw >>> ((n & ((1 << perWordBits) - 1)) << logBits)) & ((1 << bits) - 1);
277
+ return f(f(code * quantum) + minimum);
278
+ }
279
+ /**
280
+ * Every node of the tree, root first, then depth first. Leaves carry no tiles;
281
+ * use {@link leafVoxels} for their values.
282
+ */
283
+ export function treeNodes(gridWords) {
284
+ const g = grid(gridWords);
285
+ const gt = g.gt;
286
+ const out = [{ level: 3, address: g.root, origin: [0, 0, 0], parent: -1, activeTiles: [] }];
287
+ const rootNode = out[0];
288
+ const count = u32(g.words, g.root + ROOT_OFF_TABLE_SIZE);
289
+ for (let i = 0; i < count; i++) {
290
+ const t = g.root + gt.root_size + i * gt.root_tile_size;
291
+ const lo = u32(g.words, t + ROOT_TILE_OFF_KEY);
292
+ const hi = u32(g.words, t + ROOT_TILE_OFF_KEY + 4);
293
+ const key = (BigInt(hi) << 32n) | BigInt(lo);
294
+ const origin = [
295
+ Number((key >> 42n) & 0x1fffffn) << 12 | 0,
296
+ Number((key >> 21n) & 0x1fffffn) << 12 | 0,
297
+ Number(key & 0x1fffffn) << 12 | 0,
298
+ ];
299
+ const child = childOffset(g, t + ROOT_TILE_OFF_CHILD);
300
+ if (child === 0 && u32(g.words, t + ROOT_TILE_OFF_CHILD + 4) === 0) {
301
+ if (u32(g.words, t + ROOT_TILE_OFF_STATE) !== 0)
302
+ rootNode.activeTiles.push({ value: readF32(g, t + gt.root_tile_off_value), origin, dim: 4096 });
303
+ continue;
304
+ }
305
+ const upper = g.root + child;
306
+ const ui = out.push({ level: 2, address: upper, origin, parent: 0, activeTiles: [] }) - 1;
307
+ for (let un = 0; un < 32768; un++) {
308
+ const uo = [origin[0] + ((un >> 10) & 31) * 128, origin[1] + ((un >> 5) & 31) * 128, origin[2] + (un & 31) * 128];
309
+ const ut = upper + gt.upper_off_table + gt.table_stride * un;
310
+ if (!maskBit(g, upper + UPPER_OFF_CHILD_MASK, un)) {
311
+ if (maskBit(g, upper + UPPER_OFF_VALUE_MASK, un))
312
+ out[ui].activeTiles.push({ value: readF32(g, ut), origin: uo, dim: 128 });
313
+ continue;
314
+ }
315
+ const lower = upper + childOffset(g, ut);
316
+ const li = out.push({ level: 1, address: lower, origin: uo, parent: ui, activeTiles: [] }) - 1;
317
+ for (let ln = 0; ln < 4096; ln++) {
318
+ const lo3 = [uo[0] + ((ln >> 8) & 15) * 8, uo[1] + ((ln >> 4) & 15) * 8, uo[2] + (ln & 15) * 8];
319
+ const lt = lower + gt.lower_off_table + gt.table_stride * ln;
320
+ if (!maskBit(g, lower + LOWER_OFF_CHILD_MASK, ln)) {
321
+ if (maskBit(g, lower + LOWER_OFF_VALUE_MASK, ln))
322
+ out[li].activeTiles.push({ value: readF32(g, lt), origin: lo3, dim: 8 });
323
+ continue;
324
+ }
325
+ out.push({ level: 0, address: lower + childOffset(g, lt), origin: lo3, parent: li, activeTiles: [] });
326
+ }
327
+ }
328
+ }
329
+ return out;
330
+ }
331
+ /** A leaf's 512 decoded values (f32, WGSL decode order) and active flags, x-major (`n = x*64 + y*8 + z`). */
332
+ export function leafVoxels(gridWords, leafAddress) {
333
+ const g = grid(gridWords);
334
+ const values = new Float32Array(512);
335
+ const active = new Uint8Array(512);
336
+ for (let n = 0; n < 512; n++) {
337
+ values[n] = leafValue(g, leafAddress, n);
338
+ active[n] = maskBit(g, leafAddress + LEAF_OFF_VALUE_MASK, n) ? 1 : 0;
339
+ }
340
+ return { values, active };
341
+ }
342
+ function posToVoxel(pos, dim) {
343
+ const mask = ~(dim - 1);
344
+ return [Math.floor(pos[0]) & mask, Math.floor(pos[1]) & mask, Math.floor(pos[2]) & mask];
345
+ }
346
+ function rayStart(o, t, d) {
347
+ return [f(o[0] + f(d[0] * t)), f(o[1] + f(d[1] * t)), f(o[2] + f(d[2] * t))];
348
+ }
349
+ const f3 = (v) => [f(v[0]), f(v[1]), f(v[2])];
350
+ /** Twin of `vdbHddaInit` (vendored `pnanovdb_hdda_init`). */
351
+ export function hddaInit(origin, tmin, direction, tmax, dim) {
352
+ const o = f3(origin);
353
+ const d = f3(direction);
354
+ const h = { dim, tmin: f(tmin), tmax: f(tmax), voxel: [0, 0, 0], step: [0, 0, 0], delta: [0, 0, 0], next: [0, 0, 0] };
355
+ const pos = rayStart(o, h.tmin, d);
356
+ h.voxel = posToVoxel(pos, dim);
357
+ for (let i = 0; i < 3; i++) {
358
+ const inv = f(1 / d[i]);
359
+ if (d[i] === 0) {
360
+ h.next[i] = HDDA_FLOAT_MAX;
361
+ h.step[i] = 0;
362
+ h.delta[i] = 0;
363
+ }
364
+ else if (inv > 0) {
365
+ h.step[i] = 1;
366
+ h.next[i] = f(h.tmin + f(f(f(h.voxel[i] + dim) - pos[i]) * inv));
367
+ h.delta[i] = inv;
368
+ }
369
+ else {
370
+ h.step[i] = -1;
371
+ h.next[i] = f(h.tmin + f(f(h.voxel[i] - pos[i]) * inv));
372
+ h.delta[i] = -inv;
373
+ }
374
+ }
375
+ return h;
376
+ }
377
+ /** Twin of `vdbHddaUpdate` (vendored `pnanovdb_hdda_update`): switch to `dim`; false if already there. */
378
+ export function hddaUpdate(h, origin, direction, dim) {
379
+ if (h.dim === dim)
380
+ return false;
381
+ h.dim = dim;
382
+ const o = f3(origin);
383
+ const d = f3(direction);
384
+ const pos = rayStart(o, h.tmin, d);
385
+ h.voxel = posToVoxel(pos, dim);
386
+ for (let i = 0; i < 3; i++) {
387
+ if (h.step[i] === 0)
388
+ continue;
389
+ const inv = f(1 / d[i]);
390
+ h.next[i] = f(h.tmin + f(f(h.voxel[i] - pos[i]) * inv));
391
+ if (h.step[i] > 0)
392
+ h.next[i] = f(h.next[i] + f(dim * inv));
393
+ }
394
+ return true;
395
+ }
396
+ /** Twin of `vdbHddaStep` (vendored `pnanovdb_hdda_step`, with PNANOVDB_ENFORCE_FORWARD_STEPPING). */
397
+ export function hddaStep(h) {
398
+ const n = h.next;
399
+ const a = n[0] < n[1] && n[0] < n[2] ? 0 : n[1] < n[2] ? 1 : 2;
400
+ if (n[a] <= h.tmin)
401
+ n[a] = f(n[a] + f(f(h.tmin - f(FORWARD_SCALE * n[a])) + FORWARD_BIAS));
402
+ h.tmin = n[a];
403
+ n[a] = f(n[a] + f(h.dim * h.delta[a]));
404
+ h.voxel[a] = (h.voxel[a] + h.dim * h.step[a]) | 0;
405
+ return h.tmin <= h.tmax;
406
+ }
407
+ /** The grid's index bbox (root bbox, inclusive): the pool record's `indexBBoxMin/Max`. */
408
+ export function indexBBox(gridWords) {
409
+ const g = grid(gridWords);
410
+ const i = (a) => u32(g.words, a) | 0;
411
+ return {
412
+ min: [i(g.root + ROOT_OFF_BBOX_MIN), i(g.root + ROOT_OFF_BBOX_MIN + 4), i(g.root + ROOT_OFF_BBOX_MIN + 8)],
413
+ max: [i(g.root + ROOT_OFF_BBOX_MAX), i(g.root + ROOT_OFF_BBOX_MAX + 4), i(g.root + ROOT_OFF_BBOX_MAX + 8)],
414
+ };
415
+ }
416
+ /**
417
+ * Twin of `vdbRayClip(g, o, d, &t)`: clip `[t0, t1]` to the voxel-cell box
418
+ * `[min, max + 1]` (vendored `hdda_ray_clip`); hit if the clipped interval is
419
+ * non-empty. NaN handling (an axis-parallel ray starting exactly on a slab
420
+ * plane) follows JS `Math.min/max`, which a GPU need not match.
421
+ */
422
+ export function rayClip(gridWords, origin, direction, t) {
423
+ const { min, max } = indexBBox(gridWords);
424
+ return clipBox([min[0], min[1], min[2]], [max[0] + 1, max[1] + 1, max[2] + 1], origin, direction, t);
425
+ }
426
+ /**
427
+ * Twin of the opt-in `vdbRayClipSupport(g, o, d, &t)` (helper
428
+ * `'rayClipSupport'`): clip `[t0, t1]` to the box where `vdbSample` can read
429
+ * the grid's voxels, `[min - 1, max + 1]` for trilinear and
430
+ * `[min - 0.5, max + 0.5]` for nearest. Unlike {@link rayClip}'s
431
+ * `[min, max + 1]` it keeps the min-side half of the trilinear support.
432
+ */
433
+ export function rayClipSupport(gridWords, origin, direction, t, options = {}) {
434
+ const { min, max } = indexBBox(gridWords);
435
+ const pad = options.sampler === "nearest" ? 0.5 : 1;
436
+ return clipBox([f(min[0] - pad), f(min[1] - pad), f(min[2] - pad)], [f(max[0] + pad), f(max[1] + pad), f(max[2] + pad)], origin, direction, t);
437
+ }
438
+ /** The vendored `hdda_ray_clip` slab test against `[lo, hi]` (f32 box corners). */
439
+ function clipBox(lo, hi, origin, direction, t) {
440
+ const o = f3(origin);
441
+ const d = f3(direction);
442
+ const near = [];
443
+ const far = [];
444
+ for (let i = 0; i < 3; i++) {
445
+ const inv = f(1 / d[i]);
446
+ const a = f(f(lo[i] - o[i]) * inv);
447
+ const b = f(f(hi[i] - o[i]) * inv);
448
+ near.push(Math.min(a, b));
449
+ far.push(Math.max(a, b));
450
+ }
451
+ const tnear = Math.max(near[0], Math.max(near[1], near[2]));
452
+ const tfar = Math.min(far[0], Math.min(far[1], far[2]));
453
+ const hit = tnear <= tfar;
454
+ const t0 = Math.max(f(t[0]), tnear);
455
+ const t1 = Math.min(f(t[1]), tfar);
456
+ return { hit: hit && t0 <= t1, t0, t1 };
457
+ }
458
+ /**
459
+ * Twin of the opt-in `vdbHddaCellEnd(&h)` (helper `'hddaCellEnd'`): the ray
460
+ * `t` where the HDDA's current cell ends, `min(next, tmax)`.
461
+ */
462
+ export function hddaCellEnd(h) {
463
+ return Math.min(Math.min(h.next[0], h.next[1]), Math.min(h.next[2], h.tmax));
464
+ }
465
+ /**
466
+ * Twin of the opt-in `vdbCellBoundTrilinear(acc, ijk, dim)` (helper
467
+ * `'cellBoundTrilinear'`): the max of {@link nodeMax} over the 2x2x2 block of
468
+ * aligned `dim`-cells whose min corner is the cell holding `ijk`. It bounds
469
+ * every trilinear sample whose base voxel `floor(p)` lies in that cell,
470
+ * provided every inactive leaf voxel is <= its leaf's max (stats bound active
471
+ * values only; true of fog volumes).
472
+ */
473
+ export function cellBoundTrilinear(gridWords, ijk, dim, options = {}) {
474
+ let m = nodeMax(gridWords, ijk, dim, options);
475
+ for (let k = 1; k < 8; k++) {
476
+ const c = [ijk[0] + (k & 1) * dim, ijk[1] + ((k >> 1) & 1) * dim, ijk[2] + ((k >> 2) & 1) * dim];
477
+ m = Math.max(m, nodeMax(gridWords, c, dim, options));
478
+ }
479
+ return m;
480
+ }
481
+ /**
482
+ * Twin of the opt-in `vdbNodeAverage(acc, ijk, dim)` (helper `'nodeAverage'`,
483
+ * K3.2): the box mean of the aligned `dim`-cell holding `ijk` from node
484
+ * statistics. A cell inside one tile (or the background) is the tile's value;
485
+ * without stats (or `dim <= 1`) the value at `ijk`; `dim <= 8`: the leaf's
486
+ * `ave * activeVoxels / 512` (exact for fog leaves, whose inactive voxels are
487
+ * 0); larger: the lower node's `ave` (mean of its ACTIVE voxels; `dim` is meant
488
+ * to be 8 or 128). f32 arithmetic in WGSL order.
489
+ */
490
+ export function nodeAverage(gridWords, ijk, dim) {
491
+ const g = grid(gridWords);
492
+ const path = locate(g, ijk);
493
+ const a = DIM_OF_LEVEL[path.level];
494
+ if ((a > 1 && dim <= a) || !g.hasStats || dim <= 1)
495
+ return vdbReadValueF32(gridWords, ijk);
496
+ if (dim <= 8) {
497
+ let n = 0;
498
+ for (let w = 0; w < 16; w++) {
499
+ let v = u32(g.words, path.leaf + LEAF_OFF_VALUE_MASK + 4 * w);
500
+ while (v) {
501
+ v &= v - 1;
502
+ n++;
503
+ }
504
+ }
505
+ return f(nodeStats(gridWords, 0, path.leaf).ave * f(n / 512));
506
+ }
507
+ return nodeStats(gridWords, 1, path.lower).ave;
508
+ }
509
+ /**
510
+ * The canonical `march` walk, built only from the profile's calls (the GPU
511
+ * probe kernel in scripts/lib/march-probe.mjs is the same loop in WGSL):
512
+ *
513
+ * ```
514
+ * t = [tmin, tmax]; if !vdbRayClip(g, o, d, &t) { return; }
515
+ * vdbHddaInit(&h, o, t.x, d, t.y, max(vdbGetDim(&a, floor(o + d * t.x)), leafDim));
516
+ * loop {
517
+ * want = max(vdbGetDim(&a, h.voxel), leafDim); // probe the cell's corner
518
+ * if want != h.dim && updates < 2 { vdbHddaUpdate(&h, o, d, want); updates++; continue; }
519
+ * updates = 0;
520
+ * emit (h.voxel, h.dim, h.tmin, min(h.next, h.tmax), active, vdbNodeMax(&a, h.voxel, h.dim));
521
+ * if !vdbHddaStep(&h) { break; }
522
+ * }
523
+ * ```
524
+ *
525
+ * The corner decides the cell: a tile of size >= dim holding the corner holds
526
+ * the whole aligned cell. `vdbHddaUpdate` re-derives the cell from
527
+ * `floor(o + d * h.tmin)`, which on the entry face can name the previous cell;
528
+ * that yields a zero-length cell and the vendored forward-stepping moves on.
529
+ * Every emitted cell is classified from its own corner, so classification is
530
+ * valid even for those. At most two updates per cell keep the loop finite.
531
+ * `vdbHddaStep` continues while `tmin <= tmax`, so the last cell can be a
532
+ * zero-length one at the exit face.
533
+ */
534
+ export function hddaWalk(gridWords, origin, direction, options = {}) {
535
+ const leafDim = options.leafDim ?? 8;
536
+ const threshold = options.threshold ?? -Infinity;
537
+ const maxSteps = options.maxSteps ?? 1 << 16;
538
+ const o = f3(origin);
539
+ const d = f3(direction);
540
+ const clip = rayClip(gridWords, o, d, [options.tmin ?? 0, options.tmax ?? 3.4e38]);
541
+ if (!clip.hit)
542
+ return [];
543
+ const cellDim = (ijk) => Math.max(getDim(gridWords, ijk), leafDim);
544
+ const start = rayStart(o, clip.t0, d);
545
+ const h = hddaInit(o, clip.t0, d, clip.t1, cellDim([Math.floor(start[0]), Math.floor(start[1]), Math.floor(start[2])]));
546
+ const out = [];
547
+ let updates = 0;
548
+ for (let i = 0; i < maxSteps; i++) {
549
+ const a = getDim(gridWords, h.voxel);
550
+ const want = Math.max(a, leafDim);
551
+ if (want !== h.dim && updates < 2) {
552
+ hddaUpdate(h, o, d, want);
553
+ updates++;
554
+ continue;
555
+ }
556
+ updates = 0;
557
+ const voxel = [h.voxel[0], h.voxel[1], h.voxel[2]];
558
+ const active = a >= h.dim ? isActive(gridWords, voxel) : true;
559
+ const max = nodeMax(gridWords, voxel, h.dim, options.valueMax === undefined ? {} : { valueMax: options.valueMax });
560
+ out.push({
561
+ level: a === 1 ? 0 : a === 8 ? 1 : a === 128 ? 2 : 3,
562
+ dim: h.dim,
563
+ voxel,
564
+ t0: h.tmin,
565
+ t1: hddaCellEnd(h),
566
+ active,
567
+ max,
568
+ skip: !active || max < threshold,
569
+ });
570
+ if (!hddaStep(h))
571
+ break;
572
+ }
573
+ return out;
574
+ }
575
+ //# sourceMappingURL=march.js.map