@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,182 @@
1
+ // Portions derived from mjurczyk/openvdb (MIT), commit 75e7345 (v0.26.0):
2
+ // src/three-openvdb/frame/webgpu/FrameVolumeShadows.js L42–53 (constants), L130–143 (getCascadeBreaks),
3
+ // L248–290 (getCascadeLookup), L344–372 (the receiver transmittance), L704–731 (the cascade far distance of
4
+ // fitCascades); src/three-openvdb/frame/webgpu/FrameVolumeShadowMaterial.js L27–48 (constants,
5
+ // frameShadowDepth), L90–172 (the Beer shadow map pass).
6
+ // Copyright (c) mjurczyk/openvdb contributors. Licensed under the MIT License (see THIRD_PARTY_NOTICES.md).
7
+ // Changes: engine-free TypeScript CPU twins (f64) of his mesh-shadow maths; matrices are column-major
8
+ // arrays (three's `elements`). Divergences: none (twins of the ported TSL).
9
+ /** Optical depth below this casts no shadow (his `minOpticalDepth`). */
10
+ export const frameShadowMinOpticalDepth = 1e-4;
11
+ /** The march stops past this optical depth (transmittance below e⁻⁸; his `maxOpticalDepth`). */
12
+ export const frameShadowMaxOpticalDepth = 8.0;
13
+ /** Upper limit of `castShadowSteps` (his `frameMaxShadowSteps`). */
14
+ export const frameMaxCastShadowSteps = 256;
15
+ /** Directional lights: cascades of the view, tiles of one atlas (his `frameMaxShadowMapCascades`). */
16
+ export const frameMaxShadowMapCascades = 4;
17
+ /** Distance in front of the cascade bounds and the volume box, along the light (his `cascadeMargin`). */
18
+ export const frameShadowCascadeMargin = 1.0;
19
+ /** `castShadowCoarse`: map size and samples (his `coarseMapSize`, `coarseSteps`). */
20
+ export const frameShadowCoarseMapSize = 64;
21
+ export const frameShadowCoarseSteps = 8;
22
+ const sub = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
23
+ const dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
24
+ const len = (a) => Math.sqrt(dot(a, a));
25
+ const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
26
+ /** frameShadowDepth: depth of a world point for a shadow camera (distance, or along the forward axis). */
27
+ export function vdbFrameShadowDepth(ray, world) {
28
+ const offset = sub(world, ray.origin);
29
+ return ray.perspective === 1 ? len(offset) : dot(offset, ray.forward);
30
+ }
31
+ /** Column-major 4×4 times (x, y, z, w). */
32
+ function mul4(m, v) {
33
+ const out = [0, 0, 0, 0];
34
+ for (let r = 0; r < 4; r++)
35
+ out[r] = m[r] * v[0] + m[4 + r] * v[1] + m[8 + r] * v[2] + m[12 + r] * v[3];
36
+ return out;
37
+ }
38
+ /**
39
+ * The pass ray of one map texel (FrameVolumeShadowMaterial L90–109): two unprojected points of the pixel ray at
40
+ * NDC depth 0.25 and 0.75 give the direction; perspective rays start at the camera, orthographic ones on the camera
41
+ * plane. `ndc` is the pixel centre in [−1, 1]² (y up); matrices are the shadow camera's, column-major.
42
+ */
43
+ export function vdbFrameShadowPassRay(projection, projectionInverse, cameraWorld, ndc) {
44
+ const unproject = (z) => {
45
+ const view = mul4(projectionInverse, [ndc[0], ndc[1], z, 1]);
46
+ const world = mul4(cameraWorld, [view[0] / view[3], view[1] / view[3], view[2] / view[3], 1]);
47
+ return [world[0], world[1], world[2]];
48
+ };
49
+ const near = unproject(0.25);
50
+ const far = unproject(0.75);
51
+ const d = sub(far, near);
52
+ const l = len(d);
53
+ const direction = [d[0] / l, d[1] / l, d[2] / l];
54
+ const cameraPosition = [cameraWorld[12], cameraWorld[13], cameraWorld[14]];
55
+ const perspective = projection[15] < 0.5;
56
+ if (perspective)
57
+ return { origin: cameraPosition, direction };
58
+ const along = dot(sub(near, cameraPosition), direction);
59
+ return { origin: [near[0] - direction[0] * along, near[1] - direction[1] * along, near[2] - direction[2] * along], direction };
60
+ }
61
+ /**
62
+ * One texel of the Beer shadow map (FrameVolumeShadowMaterial L111–172): `steps` samples of the light ray through
63
+ * `box` (the last grid cascade), each at the middle of its step; the march stops past optical depth 8. Returns
64
+ * (τ·first, τ·last, 0, τ) with first / last the depths (÷ `ray.far`) of the first and last non-empty steps; empty
65
+ * texels are 0. `extinctionAt` is the grid extinction (red channel of the shadow density grid) at a world point.
66
+ * Spectral (`extinctionAt` returns rgb): output 0 is (τ̄·first, τ̄·last, 0, τ̄) with τ̄ the channel mean, output 1
67
+ * is (τ rgb, 0).
68
+ */
69
+ export function vdbFrameShadowMapTexel(extinctionAt, origin, direction, box, steps, ray, spectral = false) {
70
+ const depth = [0, 0, 0];
71
+ const total = () => (spectral ? Math.min(depth[0], depth[1], depth[2]) : depth[0]);
72
+ let first = 0;
73
+ let last = 0;
74
+ if (box) {
75
+ const tMin = [];
76
+ const tMax = [];
77
+ for (let c = 0; c < 3; c++) {
78
+ const inv = 1 / direction[c];
79
+ const a = (box.min[c] - origin[c]) * inv;
80
+ const b = (box.max[c] - origin[c]) * inv;
81
+ tMin.push(Math.min(a, b));
82
+ tMax.push(Math.max(a, b));
83
+ }
84
+ const tStart = Math.max(0, Math.max(tMin[0], Math.max(tMin[1], tMin[2])));
85
+ const tEnd = Math.min(tMax[0], Math.min(tMax[1], tMax[2]));
86
+ if (tEnd > tStart) {
87
+ const n = Math.max(steps, 1);
88
+ const stepLength = (tEnd - tStart) / n;
89
+ let firstT = -1;
90
+ let lastT = -1;
91
+ for (let i = 0; i < n; i++) {
92
+ if (total() > frameShadowMaxOpticalDepth)
93
+ break;
94
+ const t = tStart + i * stepLength;
95
+ const s = t + stepLength * 0.5;
96
+ const e = extinctionAt([origin[0] + direction[0] * s, origin[1] + direction[1] * s, origin[2] + direction[2] * s]);
97
+ const ext = typeof e === "number" ? [e, e, e] : e;
98
+ const any = spectral ? ext[0] + ext[1] + ext[2] : ext[0];
99
+ if (any > 0) {
100
+ if (firstT < 0)
101
+ firstT = t;
102
+ lastT = t + stepLength;
103
+ for (let c = 0; c < 3; c++)
104
+ depth[c] = depth[c] + ext[c] * stepLength;
105
+ }
106
+ }
107
+ if ((spectral ? depth[0] + depth[1] + depth[2] : depth[0]) > 0) {
108
+ const at = (t) => [origin[0] + direction[0] * t, origin[1] + direction[1] * t, origin[2] + direction[2] * t];
109
+ first = vdbFrameShadowDepth(ray, at(firstT)) / ray.far;
110
+ last = vdbFrameShadowDepth(ray, at(lastT)) / ray.far;
111
+ }
112
+ }
113
+ }
114
+ if (spectral) {
115
+ const mean = (depth[0] + depth[1] + depth[2]) / 3;
116
+ return { map: [first * mean, last * mean, 0, mean], spectral: [depth[0], depth[1], depth[2], 0] };
117
+ }
118
+ return { map: [first * depth[0], last * depth[0], 0, depth[0]], spectral: null };
119
+ }
120
+ /**
121
+ * The receiver transmittance (FrameVolumeShadows L344–372): the optical depth grows linearly from the first to the
122
+ * last non-empty depth of the (filtered) texel. `depth` is the receiver's {@link vdbFrameShadowDepth}, `far` the
123
+ * drawn shadow camera's far. `spectralTexel` (rgb optical depth): per-channel transmittance; with `mean`, their mean
124
+ * (a `ShadowMaterial` receiver). Returns 1 for an empty texel.
125
+ */
126
+ export function vdbFrameShadowReceiver(texel, depth, far, spectralTexel = null, mean = false) {
127
+ const opticalDepth = texel[3];
128
+ if (!(opticalDepth > frameShadowMinOpticalDepth))
129
+ return spectralTexel && !mean ? [1, 1, 1] : 1;
130
+ const first = (texel[0] / opticalDepth) * far;
131
+ const last = (texel[1] / opticalDepth) * far;
132
+ const along = clamp((depth - first) / Math.max(last - first, 1e-4), 0, 1);
133
+ if (spectralTexel) {
134
+ const t = [Math.exp(-spectralTexel[0] * along), Math.exp(-spectralTexel[1] * along), Math.exp(-spectralTexel[2] * along)];
135
+ return mean ? (t[0] + t[1] + t[2]) / 3 : t;
136
+ }
137
+ return Math.exp(-opticalDepth * along);
138
+ }
139
+ /** getCascadeBreaks: far distance of each cascade, the practical split of three's CSMShadowNode (λ = 0.5). */
140
+ export function vdbFrameShadowCascadeBreaks(count, near, far) {
141
+ const breaks = [];
142
+ for (let i = 1; i <= count; i++) {
143
+ const uniformSplit = near + ((far - near) * i) / count;
144
+ const logSplit = near * Math.pow(far / near, i / count);
145
+ breaks.push(i === count ? far : uniformSplit + (logSplit - uniformSplit) * 0.5);
146
+ }
147
+ return breaks;
148
+ }
149
+ /**
150
+ * The view distance the cascades cover (fitCascades L714–730): the far corner of the volume box plus one box
151
+ * diagonal, rounded up to half octaves (so the splits move only at those steps), within [near·1.0001,
152
+ * min(camera far, castShadowDistance)]. `boxFar` is the largest view depth of the box's corners.
153
+ */
154
+ export function vdbFrameShadowCascadeFar(near, cameraFar, castShadowDistance, boxFar, boxDiagonal) {
155
+ const sceneFar = Math.max(near * 2.0, boxFar + boxDiagonal);
156
+ const steppedFar = Math.pow(2.0, Math.ceil(Math.log2(sceneFar) * 2.0) / 2.0);
157
+ return Math.max(near * 1.0001, Math.min(cameraFar, castShadowDistance, steppedFar));
158
+ }
159
+ /** The cascade of a receiver (getCascadeLookup L253–261): the number of cascade far distances in front of it. */
160
+ export function vdbFrameShadowCascadeIndex(viewDepth, breaks, count) {
161
+ let index = 0;
162
+ for (let i = 0; i < frameMaxShadowMapCascades - 1; i++)
163
+ if (viewDepth > breaks[i] && i + 1 < count)
164
+ index++;
165
+ return index;
166
+ }
167
+ /**
168
+ * The atlas uv of a receiver in cascade `index` (getCascadeLookup L266–282): `clip` is its clip position in the
169
+ * cascade camera (x, y after the divide; orthographic, so w = 1). Half a texel in from each tile side. `inside`
170
+ * also needs the view depth within the last break (checked by the caller).
171
+ */
172
+ export function vdbFrameShadowCascadeUv(clip, index, size) {
173
+ const tileUv = [clip[0] * 0.5 + 0.5, 0.5 - clip[1] * 0.5];
174
+ const inset = 0.5 / size;
175
+ const u = clamp(tileUv[0], inset, 1 - inset);
176
+ const v = clamp(tileUv[1], inset, 1 - inset);
177
+ return {
178
+ uv: [(u + index) / frameMaxShadowMapCascades, v],
179
+ insideTile: tileUv[0] >= 0 && tileUv[0] <= 1 && tileUv[1] >= 0 && tileUv[1] <= 1,
180
+ };
181
+ }
182
+ //# sourceMappingURL=shadows.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shadows.js","sourceRoot":"","sources":["../../../src/tools/frame/shadows.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,0GAA0G;AAC1G,8GAA8G;AAC9G,iGAAiG;AACjG,2DAA2D;AAC3D,4GAA4G;AAC5G,sGAAsG;AACtG,4EAA4E;AAU5E,wEAAwE;AACxE,MAAM,CAAC,MAAM,0BAA0B,GAAG,IAAI,CAAC;AAC/C,gGAAgG;AAChG,MAAM,CAAC,MAAM,0BAA0B,GAAG,GAAG,CAAC;AAC9C,oEAAoE;AACpE,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAC3C,sGAAsG;AACtG,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC;AAC3C,yGAAyG;AACzG,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,CAAC;AAC5C,qFAAqF;AACrF,MAAM,CAAC,MAAM,wBAAwB,GAAG,EAAE,CAAC;AAC3C,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC;AAYxC,MAAM,GAAG,GAAG,CAAC,CAAO,EAAE,CAAO,EAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAChF,MAAM,GAAG,GAAG,CAAC,CAAO,EAAE,CAAO,EAAU,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAA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u/FrameVolumeShadows.js L42–53 (constants), L130–143 (getCascadeBreaks),\n// L248–290 (getCascadeLookup), L344–372 (the receiver transmittance), L704–731 (the cascade far distance of\n// fitCascades); src/three-openvdb/frame/webgpu/FrameVolumeShadowMaterial.js L27–48 (constants,\n// frameShadowDepth), L90–172 (the Beer shadow map pass).\n// Copyright (c) mjurczyk/openvdb contributors. Licensed under the MIT License (see THIRD_PARTY_NOTICES.md).\n// Changes: engine-free TypeScript CPU twins (f64) of his mesh-shadow maths; matrices are column-major\n// arrays (three's `elements`). Divergences: none (twins of the ported TSL).\n\n/**\n * K3.6: CPU twins of the volume shadows on meshes (his `FrameVolumeShadows` / `FrameVolumeShadowMaterial`):\n * the Beer shadow map pass (one texel: a light ray marched through the last grid cascade), the receiver\n * lookup (transmittance at a mesh point from the map), the directional-light cascade split and its lookup.\n */\n\nimport type { Vec2, Vec3, Vec4 } from \"./index.js\";\n\n/** Optical depth below this casts no shadow (his `minOpticalDepth`). */\nexport const frameShadowMinOpticalDepth = 1e-4;\n/** The march stops past this optical depth (transmittance below e⁻⁸; his `maxOpticalDepth`). */\nexport const frameShadowMaxOpticalDepth = 8.0;\n/** Upper limit of `castShadowSteps` (his `frameMaxShadowSteps`). */\nexport const frameMaxCastShadowSteps = 256;\n/** Directional lights: cascades of the view, tiles of one atlas (his `frameMaxShadowMapCascades`). */\nexport const frameMaxShadowMapCascades = 4;\n/** Distance in front of the cascade bounds and the volume box, along the light (his `cascadeMargin`). */\nexport const frameShadowCascadeMargin = 1.0;\n/** `castShadowCoarse`: map size and samples (his `coarseMapSize`, `coarseSteps`). */\nexport const frameShadowCoarseMapSize = 64;\nexport const frameShadowCoarseSteps = 8;\n\n/** The ray uniforms of one shadow camera (his `createShadowRayUniforms`). */\nexport interface VDBFrameShadowRay {\n origin: Vec3;\n forward: Vec3;\n /** 1: depth is the distance from the origin (perspective). 0: along `forward` (orthographic). */\n perspective: number;\n /** Far plane of the shadow camera; map depths are divided by it. */\n far: number;\n}\n\nconst sub = (a: Vec3, b: Vec3): Vec3 => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];\nconst dot = (a: Vec3, b: Vec3): number => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];\nconst len = (a: Vec3): number => Math.sqrt(dot(a, a));\nconst clamp = (v: number, lo: number, hi: number): number => Math.min(hi, Math.max(lo, v));\n\n/** frameShadowDepth: depth of a world point for a shadow camera (distance, or along the forward axis). */\nexport function vdbFrameShadowDepth(ray: Pick<VDBFrameShadowRay, \"origin\" | \"forward\" | \"perspective\">, world: Vec3): number {\n const offset = sub(world, ray.origin);\n return ray.perspective === 1 ? len(offset) : dot(offset, ray.forward);\n}\n\n/** Column-major 4×4 times (x, y, z, w). */\nfunction mul4(m: ArrayLike<number>, v: Vec4): Vec4 {\n const out: Vec4 = [0, 0, 0, 0];\n for (let r = 0; r < 4; r++) out[r] = m[r]! * v[0] + m[4 + r]! * v[1] + m[8 + r]! * v[2] + m[12 + r]! * v[3];\n return out;\n}\n\n/**\n * The pass ray of one map texel (FrameVolumeShadowMaterial L90–109): two unprojected points of the pixel ray at\n * NDC depth 0.25 and 0.75 give the direction; perspective rays start at the camera, orthographic ones on the camera\n * plane. `ndc` is the pixel centre in [−1, 1]² (y up); matrices are the shadow camera's, column-major.\n */\nexport function vdbFrameShadowPassRay(projection: ArrayLike<number>, projectionInverse: ArrayLike<number>, cameraWorld: ArrayLike<number>, ndc: Vec2): { origin: Vec3; direction: Vec3 } {\n const unproject = (z: number): Vec3 => {\n const view = mul4(projectionInverse, [ndc[0], ndc[1], z, 1]);\n const world = mul4(cameraWorld, [view[0] / view[3], view[1] / view[3], view[2] / view[3], 1]);\n return [world[0], world[1], world[2]];\n };\n const near = unproject(0.25);\n const far = unproject(0.75);\n const d = sub(far, near);\n const l = len(d);\n const direction: Vec3 = [d[0] / l, d[1] / l, d[2] / l];\n const cameraPosition: Vec3 = [cameraWorld[12]!, cameraWorld[13]!, cameraWorld[14]!];\n const perspective = projection[15]! < 0.5;\n if (perspective) return { origin: cameraPosition, direction };\n const along = dot(sub(near, cameraPosition), direction);\n return { origin: [near[0] - direction[0] * along, near[1] - direction[1] * along, near[2] - direction[2] * along], direction };\n}\n\n/**\n * One texel of the Beer shadow map (FrameVolumeShadowMaterial L111–172): `steps` samples of the light ray through\n * `box` (the last grid cascade), each at the middle of its step; the march stops past optical depth 8. Returns\n * (τ·first, τ·last, 0, τ) with first / last the depths (÷ `ray.far`) of the first and last non-empty steps; empty\n * texels are 0. `extinctionAt` is the grid extinction (red channel of the shadow density grid) at a world point.\n * Spectral (`extinctionAt` returns rgb): output 0 is (τ̄·first, τ̄·last, 0, τ̄) with τ̄ the channel mean, output 1\n * is (τ rgb, 0).\n */\nexport function vdbFrameShadowMapTexel(\n extinctionAt: (world: Vec3) => number | Vec3,\n origin: Vec3,\n direction: Vec3,\n box: { min: Vec3; max: Vec3 } | null,\n steps: number,\n ray: VDBFrameShadowRay,\n spectral = false,\n): { map: Vec4; spectral: Vec4 | null } {\n const depth: Vec3 = [0, 0, 0];\n const total = () => (spectral ? Math.min(depth[0], depth[1], depth[2]) : depth[0]);\n let first = 0;\n let last = 0;\n if (box) {\n const tMin: number[] = [];\n const tMax: number[] = [];\n for (let c = 0; c < 3; c++) {\n const inv = 1 / direction[c]!;\n const a = (box.min[c]! - origin[c]!) * inv;\n const b = (box.max[c]! - origin[c]!) * inv;\n tMin.push(Math.min(a, b));\n tMax.push(Math.max(a, b));\n }\n const tStart = Math.max(0, Math.max(tMin[0]!, Math.max(tMin[1]!, tMin[2]!)));\n const tEnd = Math.min(tMax[0]!, Math.min(tMax[1]!, tMax[2]!));\n if (tEnd > tStart) {\n const n = Math.max(steps, 1);\n const stepLength = (tEnd - tStart) / n;\n let firstT = -1;\n let lastT = -1;\n for (let i = 0; i < n; i++) {\n if (total() > frameShadowMaxOpticalDepth) break;\n const t = tStart + i * stepLength;\n const s = t + stepLength * 0.5;\n const e = extinctionAt([origin[0] + direction[0] * s, origin[1] + direction[1] * s, origin[2] + direction[2] * s]);\n const ext: Vec3 = typeof e === \"number\" ? [e, e, e] : e;\n const any = spectral ? ext[0] + ext[1] + ext[2] : ext[0];\n if (any > 0) {\n if (firstT < 0) firstT = t;\n lastT = t + stepLength;\n for (let c = 0; c < 3; c++) depth[c] = depth[c]! + ext[c]! * stepLength;\n }\n }\n if ((spectral ? depth[0] + depth[1] + depth[2] : depth[0]) > 0) {\n const at = (t: number): Vec3 => [origin[0] + direction[0] * t, origin[1] + direction[1] * t, origin[2] + direction[2] * t];\n first = vdbFrameShadowDepth(ray, at(firstT)) / ray.far;\n last = vdbFrameShadowDepth(ray, at(lastT)) / ray.far;\n }\n }\n }\n if (spectral) {\n const mean = (depth[0] + depth[1] + depth[2]) / 3;\n return { map: [first * mean, last * mean, 0, mean], spectral: [depth[0], depth[1], depth[2], 0] };\n }\n return { map: [first * depth[0], last * depth[0], 0, depth[0]], spectral: null };\n}\n\n/**\n * The receiver transmittance (FrameVolumeShadows L344–372): the optical depth grows linearly from the first to the\n * last non-empty depth of the (filtered) texel. `depth` is the receiver's {@link vdbFrameShadowDepth}, `far` the\n * drawn shadow camera's far. `spectralTexel` (rgb optical depth): per-channel transmittance; with `mean`, their mean\n * (a `ShadowMaterial` receiver). Returns 1 for an empty texel.\n */\nexport function vdbFrameShadowReceiver(texel: Vec4, depth: number, far: number, spectralTexel: Vec3 | null = null, mean = false): number | Vec3 {\n const opticalDepth = texel[3];\n if (!(opticalDepth > frameShadowMinOpticalDepth)) return spectralTexel && !mean ? [1, 1, 1] : 1;\n const first = (texel[0] / opticalDepth) * far;\n const last = (texel[1] / opticalDepth) * far;\n const along = clamp((depth - first) / Math.max(last - first, 1e-4), 0, 1);\n if (spectralTexel) {\n const t: Vec3 = [Math.exp(-spectralTexel[0] * along), Math.exp(-spectralTexel[1] * along), Math.exp(-spectralTexel[2] * along)];\n return mean ? (t[0] + t[1] + t[2]) / 3 : t;\n }\n return Math.exp(-opticalDepth * along);\n}\n\n/** getCascadeBreaks: far distance of each cascade, the practical split of three's CSMShadowNode (λ = 0.5). */\nexport function vdbFrameShadowCascadeBreaks(count: number, near: number, far: number): number[] {\n const breaks: number[] = [];\n for (let i = 1; i <= count; i++) {\n const uniformSplit = near + ((far - near) * i) / count;\n const logSplit = near * Math.pow(far / near, i / count);\n breaks.push(i === count ? far : uniformSplit + (logSplit - uniformSplit) * 0.5);\n }\n return breaks;\n}\n\n/**\n * The view distance the cascades cover (fitCascades L714–730): the far corner of the volume box plus one box\n * diagonal, rounded up to half octaves (so the splits move only at those steps), within [near·1.0001,\n * min(camera far, castShadowDistance)]. `boxFar` is the largest view depth of the box's corners.\n */\nexport function vdbFrameShadowCascadeFar(near: number, cameraFar: number, castShadowDistance: number, boxFar: number, boxDiagonal: number): number {\n const sceneFar = Math.max(near * 2.0, boxFar + boxDiagonal);\n const steppedFar = Math.pow(2.0, Math.ceil(Math.log2(sceneFar) * 2.0) / 2.0);\n return Math.max(near * 1.0001, Math.min(cameraFar, castShadowDistance, steppedFar));\n}\n\n/** The cascade of a receiver (getCascadeLookup L253–261): the number of cascade far distances in front of it. */\nexport function vdbFrameShadowCascadeIndex(viewDepth: number, breaks: readonly number[], count: number): number {\n let index = 0;\n for (let i = 0; i < frameMaxShadowMapCascades - 1; i++) if (viewDepth > breaks[i]! && i + 1 < count) index++;\n return index;\n}\n\n/**\n * The atlas uv of a receiver in cascade `index` (getCascadeLookup L266–282): `clip` is its clip position in the\n * cascade camera (x, y after the divide; orthographic, so w = 1). Half a texel in from each tile side. `inside`\n * also needs the view depth within the last break (checked by the caller).\n */\nexport function vdbFrameShadowCascadeUv(clip: Vec2, index: number, size: number): { uv: Vec2; insideTile: boolean } {\n const tileUv: Vec2 = [clip[0] * 0.5 + 0.5, 0.5 - clip[1] * 0.5];\n const inset = 0.5 / size;\n const u = clamp(tileUv[0], inset, 1 - inset);\n const v = clamp(tileUv[1], inset, 1 - inset);\n return {\n uv: [(u + index) / frameMaxShadowMapCascades, v],\n insideTile: tileUv[0] >= 0 && tileUv[0] <= 1 && tileUv[1] >= 0 && tileUv[1] <= 1,\n };\n}\n"]}
@@ -0,0 +1,65 @@
1
+ import { type Vec3 } from "../cpu/march.js";
2
+ import { vdbPyramidBaseLevel } from "./pyramid-layout.js";
3
+ export { vdbPyramidBaseLevel };
4
+ /** A float mip atlas in his layout: levels 1..n side by side on x. */
5
+ export interface VDBFloatMipAtlas {
6
+ readonly data: Float32Array;
7
+ readonly dimensions: [number, number, number];
8
+ /** Levels in the atlas (above the base). */
9
+ readonly levels: number;
10
+ }
11
+ /**
12
+ * His box mip atlas (frameMipmaps.js `buildAtlas` / `packAtlas` / `downsample`) over float data:
13
+ * levels 1..n with n = ⌈log2(max side)⌉, each the 2x2x2 mean of the level below with edge taps
14
+ * clamped; level l at x = atlasWidth − atlasWidth / 2^(l−1). No 8-bit rounding. Null for a 1³ base.
15
+ */
16
+ export declare function vdbBoxMipAtlasF32(data: Float32Array, dimensions: readonly number[]): VDBFloatMipAtlas | null;
17
+ /** Options of {@link vdbBoxPyramid}. */
18
+ export interface VDBBoxPyramidOptions {
19
+ /** Inclusive voxel index box the volume's unit box covers. Default: the grid's index bbox. */
20
+ indexBox?: {
21
+ min: Vec3;
22
+ max: Vec3;
23
+ };
24
+ /** Texels on the longest side of the base level at most (R1: `pyramidMax`, default 128). */
25
+ pyramidMax?: number;
26
+ /** Base level override (default {@link vdbPyramidBaseLevel}). */
27
+ level?: number;
28
+ }
29
+ /** The dense coarse levels of a sparse grid (see the file comment). */
30
+ export interface VDBBoxPyramid {
31
+ /** L₀: the level of `data` in level-0 voxels (texel footprint 2^L₀). */
32
+ readonly level: number;
33
+ /** Texels of the base level, ⌈indexBox size / 2^L₀⌉. */
34
+ readonly dimensions: [number, number, number];
35
+ /** Base level, x fastest, the box mean of the sparse grid over each texel's cell. */
36
+ readonly data: Float32Array;
37
+ /** Levels L₀+1… in his atlas layout (null when the base is 1³). */
38
+ readonly atlas: VDBFloatMipAtlas | null;
39
+ /** Total levels the source then has: L₀ + atlas levels. */
40
+ readonly lodLevels: number;
41
+ }
42
+ /**
43
+ * The coarse pyramid of a sparse FLOAT/Fp grid image (CPU, `vdbResampleGrid` box). The grid's Map must
44
+ * be axis-aligned (vdbResampleGrid's rule).
45
+ */
46
+ export declare function vdbBoxPyramid(image: Uint32Array, o?: VDBBoxPyramidOptions): VDBBoxPyramid;
47
+ /**
48
+ * Twin of the sparse source's node-average tap (`vdbFrameNodeAverage` in `three/sparse-source.ts`):
49
+ * trilinear interpolation of {@link nodeAverage} over the lattice of aligned `dim`-cells, whose
50
+ * centres are at `dim·j + dim/2 − ½` in index space (voxel centres at integers). `p` is in index
51
+ * space. f32 arithmetic in WGSL order.
52
+ */
53
+ export declare function vdbFrameNodeAverageSample(image: Uint32Array, p: Vec3, dim: number): number;
54
+ /**
55
+ * Twin of the shadow march's empty-space query (`vdbFrameSkipEmpty`, K3.2): an HDDA over 8³ cells
56
+ * of the ray `o + d·t` (sample space: index space, the trilinear base voxel is `floor(p)`) from `t0`
57
+ * to `t1`. Returns `[ts, te]`: every sample with `t < ts` reads only voxels whose bound is ≤ `cutoff`
58
+ * (so it is skipped exactly), and the cell from `ts` to `te` must be sampled; `[t1, t1]` when the
59
+ * rest is empty. The bound per cell is `cellBoundTrilinear` (the 2x2x2 block a level-0 trilinear tap
60
+ * reads) or, with `dilate`, the max of `nodeMax` over the 3x3x3 cells around (taps of the coarse
61
+ * levels that reach at most 8 voxels past the cell). After `maxCells` empty cells it returns
62
+ * `[ts, ts]` (the caller asks again from there). `ts` steps back by `1e-3` voxel along the ray so a
63
+ * sample on a cell face is never skipped by rounding.
64
+ */
65
+ export declare function vdbFrameSkipEmpty(image: Uint32Array, o: Vec3, d: Vec3, t0: number, t1: number, cutoff: number, dilate: boolean, maxCells?: number): [number, number];
@@ -0,0 +1,191 @@
1
+ // Portions derived from mjurczyk/openvdb (MIT), commit 75e7345 (v0.26.0):
2
+ // src/three-openvdb/frame/webgpu/frameMipmaps.js L14–106 (level sizes, 2x2x2 box downsample with
3
+ // clamped edge taps, the mip atlas layout), as float data.
4
+ // Copyright (c) mjurczyk/openvdb contributors. Licensed under the MIT License (see THIRD_PARTY_NOTICES.md).
5
+ // Changes: f32 data without the 8-bit rounding; the first level comes from a sparse grid through
6
+ // `vdbResampleGrid` (box); node-average sampling and the HDDA skip are ours (K3.2). Divergences:
7
+ // DIVERGES.md (K3.2 rows).
8
+ /**
9
+ * CPU side of the sparse volume source's LOD strategies (K3.2, R1 §4.3) and the CPU twins of its
10
+ * WGSL (`@pmndrs/vdb/three` `sparse-source.ts`):
11
+ *
12
+ * - `'coarse-pyramid'`: {@link vdbBoxPyramid} builds the dense coarse levels his
13
+ * `sampleExtinction(localPos, lod)` reads at lod ≥ 1. The base level L₀ = max(1, ⌈log2(maxTexels /
14
+ * pyramidMax)⌉) is a box resample of the sparse grid (`vdbResampleGrid`, filter `'box'`) to
15
+ * ⌈texels / 2^L₀⌉ voxels over the exact index box, so texel j is centred at uvw (j + 0.5) / dims as
16
+ * his mip levels are; the levels above it are his 2x2x2 box mip atlas, in float
17
+ * ({@link vdbBoxMipAtlasF32}).
18
+ * - `'node-average'`: {@link vdbFrameNodeAverageSample} is the twin of the trilinear interpolation
19
+ * of `vdbNodeAverage` over the leaf (dim 8) or lower-node (dim 128) lattice.
20
+ * - HDDA skip: {@link vdbFrameSkipEmpty} is the twin of the shadow march's empty-space query.
21
+ *
22
+ * Engine-free and core-free (D20): reads the NanoVDB image with the `tools/cpu` twins.
23
+ */
24
+ import { VDBToolsError } from "../errors.js";
25
+ import { cellBoundTrilinear, hddaCellEnd, hddaInit, hddaStep, indexBBox, leafVoxels, nodeAverage, nodeMax, treeNodes } from "../cpu/march.js";
26
+ import { vdbResampleGrid } from "../nanovdb/resample.js";
27
+ import { GRID_OFF_MAP, MAP_OFF_MATD, MAP_OFF_VECD } from "../nanovdb/bytes.js";
28
+ import { vdbBoxPyramidLayout, vdbPyramidBaseLevel, vdbPyramidLevelSize as levelSize } from "./pyramid-layout.js";
29
+ export { vdbPyramidBaseLevel };
30
+ const f = Math.fround;
31
+ /**
32
+ * His box mip atlas (frameMipmaps.js `buildAtlas` / `packAtlas` / `downsample`) over float data:
33
+ * levels 1..n with n = ⌈log2(max side)⌉, each the 2x2x2 mean of the level below with edge taps
34
+ * clamped; level l at x = atlasWidth − atlasWidth / 2^(l−1). No 8-bit rounding. Null for a 1³ base.
35
+ */
36
+ export function vdbBoxMipAtlasF32(data, dimensions) {
37
+ const [width, height, depth] = dimensions;
38
+ const count = Math.ceil(Math.log2(Math.max(width, height, depth, 1)));
39
+ if (count < 1)
40
+ return null;
41
+ const levels = [];
42
+ let level = { data, width, height, depth };
43
+ for (let index = 1; index <= count; index++) {
44
+ const tw = levelSize(level.width, 1);
45
+ const th = levelSize(level.height, 1);
46
+ const td = levelSize(level.depth, 1);
47
+ const out = new Float32Array(tw * th * td);
48
+ const src = level;
49
+ for (let z = 0; z < td; z++) {
50
+ const z0 = Math.min(z * 2, src.depth - 1);
51
+ const z1 = Math.min(z * 2 + 1, src.depth - 1);
52
+ for (let y = 0; y < th; y++) {
53
+ const y0 = Math.min(y * 2, src.height - 1);
54
+ const y1 = Math.min(y * 2 + 1, src.height - 1);
55
+ const r00 = (y0 + z0 * src.height) * src.width;
56
+ const r10 = (y1 + z0 * src.height) * src.width;
57
+ const r01 = (y0 + z1 * src.height) * src.width;
58
+ const r11 = (y1 + z1 * src.height) * src.width;
59
+ for (let x = 0; x < tw; x++) {
60
+ const x0 = Math.min(x * 2, src.width - 1);
61
+ const x1 = Math.min(x * 2 + 1, src.width - 1);
62
+ const d = src.data;
63
+ out[x + (y + z * th) * tw] =
64
+ (d[x0 + r00] + d[x1 + r00] + d[x0 + r10] + d[x1 + r10] + d[x0 + r01] + d[x1 + r01] + d[x0 + r11] + d[x1 + r11]) / 8;
65
+ }
66
+ }
67
+ }
68
+ level = { data: out, width: tw, height: th, depth: td };
69
+ levels.push(level);
70
+ }
71
+ const atlasWidth = 2 ** Math.max(Math.ceil(Math.log2(width)), levels.length);
72
+ const atlasHeight = levelSize(height, 1);
73
+ const atlasDepth = levelSize(depth, 1);
74
+ const atlas = new Float32Array(atlasWidth * atlasHeight * atlasDepth);
75
+ levels.forEach((l, levelIndex) => {
76
+ const offset = atlasWidth - atlasWidth / 2 ** levelIndex;
77
+ for (let z = 0; z < l.depth; z++) {
78
+ for (let y = 0; y < l.height; y++) {
79
+ const row = (y + z * atlasHeight) * atlasWidth + offset;
80
+ atlas.set(l.data.subarray((y + z * l.height) * l.width, (y + z * l.height + 1) * l.width), row);
81
+ }
82
+ }
83
+ });
84
+ return { data: atlas, dimensions: [atlasWidth, atlasHeight, atlasDepth], levels: levels.length };
85
+ }
86
+ /**
87
+ * The coarse pyramid of a sparse FLOAT/Fp grid image (CPU, `vdbResampleGrid` box). The grid's Map must
88
+ * be axis-aligned (vdbResampleGrid's rule).
89
+ */
90
+ export function vdbBoxPyramid(image, o = {}) {
91
+ const box = o.indexBox ?? indexBBox(image);
92
+ const texels = [box.max[0] - box.min[0] + 1, box.max[1] - box.min[1] + 1, box.max[2] - box.min[2] + 1];
93
+ if (texels.some((t) => !(t > 0)))
94
+ throw new VDBToolsError("VDB_BAD_OPTION", "vdbBoxPyramid: empty index box");
95
+ const layout = vdbBoxPyramidLayout(texels, { ...(o.pyramidMax !== undefined ? { pyramidMax: o.pyramidMax } : {}), ...(o.level !== undefined ? { level: o.level } : {}) });
96
+ const level = layout.level;
97
+ const dims = [...layout.dimensions];
98
+ // The index cell box [min − ½, max + ½] in world (NanoVDB: world = matd · ijk + vecd).
99
+ const view = new DataView(image.buffer, image.byteOffset, image.byteLength);
100
+ const mat = Array.from({ length: 9 }, (_, i) => view.getFloat64(GRID_OFF_MAP + MAP_OFF_MATD + i * 8, true));
101
+ const vec = Array.from({ length: 3 }, (_, i) => view.getFloat64(GRID_OFF_MAP + MAP_OFF_VECD + i * 8, true));
102
+ const world = (ijk) => [0, 1, 2].map((r) => mat[r * 3] * ijk[0] + mat[r * 3 + 1] * ijk[1] + mat[r * 3 + 2] * ijk[2] + vec[r]);
103
+ const lo = world([box.min[0] - 0.5, box.min[1] - 0.5, box.min[2] - 0.5]);
104
+ const hi = world([box.max[0] + 0.5, box.max[1] + 0.5, box.max[2] + 0.5]);
105
+ const coarse = vdbResampleGrid(image, { filter: "box", dimensions: dims, bbox: [lo, hi] });
106
+ // Dense readout of the resampled grid (index box [0, dims − 1]); voxels outside its leaves and tiles are background.
107
+ const data = new Float32Array(dims[0] * dims[1] * dims[2]);
108
+ const background = 0;
109
+ if (background !== 0)
110
+ data.fill(background);
111
+ const put = (x, y, z, v) => {
112
+ if (x < 0 || y < 0 || z < 0 || x >= dims[0] || y >= dims[1] || z >= dims[2])
113
+ return;
114
+ data[x + (y + z * dims[1]) * dims[0]] = v;
115
+ };
116
+ for (const node of treeNodes(coarse.image)) {
117
+ for (const t of node.activeTiles) {
118
+ for (let z = 0; z < t.dim; z++)
119
+ for (let y = 0; y < t.dim; y++)
120
+ for (let x = 0; x < t.dim; x++)
121
+ put(t.origin[0] + x, t.origin[1] + y, t.origin[2] + z, t.value);
122
+ }
123
+ if (node.level !== 0)
124
+ continue;
125
+ const { values } = leafVoxels(coarse.image, node.address);
126
+ const [ox, oy, oz] = node.origin;
127
+ for (let n = 0; n < 512; n++)
128
+ put(ox + (n >> 6), oy + ((n >> 3) & 7), oz + (n & 7), values[n]);
129
+ }
130
+ const atlas = vdbBoxMipAtlasF32(data, dims);
131
+ return { level, dimensions: dims, data, atlas, lodLevels: level + (atlas?.levels ?? 0) };
132
+ }
133
+ /**
134
+ * Twin of the sparse source's node-average tap (`vdbFrameNodeAverage` in `three/sparse-source.ts`):
135
+ * trilinear interpolation of {@link nodeAverage} over the lattice of aligned `dim`-cells, whose
136
+ * centres are at `dim·j + dim/2 − ½` in index space (voxel centres at integers). `p` is in index
137
+ * space. f32 arithmetic in WGSL order.
138
+ */
139
+ export function vdbFrameNodeAverageSample(image, p, dim) {
140
+ const fd = f(dim);
141
+ const half = f(f(0.5 * fd) - 0.5);
142
+ const q = p.map((v) => f(f(v - half) / fd));
143
+ const base = q.map(Math.floor);
144
+ const w = q.map((v, i) => f(v - base[i]));
145
+ const c = [base[0] * dim, base[1] * dim, base[2] * dim];
146
+ const v = [];
147
+ for (let k = 0; k < 8; k++)
148
+ v.push(nodeAverage(image, [c[0] + (k & 1) * dim, c[1] + ((k >> 1) & 1) * dim, c[2] + ((k >> 2) & 1) * dim], dim));
149
+ const mix = (a, b, t) => f(a + f(t * f(b - a)));
150
+ const x00 = mix(v[0], v[1], w[0]);
151
+ const x10 = mix(v[2], v[3], w[0]);
152
+ const x01 = mix(v[4], v[5], w[0]);
153
+ const x11 = mix(v[6], v[7], w[0]);
154
+ return mix(mix(x00, x10, w[1]), mix(x01, x11, w[1]), w[2]);
155
+ }
156
+ /**
157
+ * Twin of the shadow march's empty-space query (`vdbFrameSkipEmpty`, K3.2): an HDDA over 8³ cells
158
+ * of the ray `o + d·t` (sample space: index space, the trilinear base voxel is `floor(p)`) from `t0`
159
+ * to `t1`. Returns `[ts, te]`: every sample with `t < ts` reads only voxels whose bound is ≤ `cutoff`
160
+ * (so it is skipped exactly), and the cell from `ts` to `te` must be sampled; `[t1, t1]` when the
161
+ * rest is empty. The bound per cell is `cellBoundTrilinear` (the 2x2x2 block a level-0 trilinear tap
162
+ * reads) or, with `dilate`, the max of `nodeMax` over the 3x3x3 cells around (taps of the coarse
163
+ * levels that reach at most 8 voxels past the cell). After `maxCells` empty cells it returns
164
+ * `[ts, ts]` (the caller asks again from there). `ts` steps back by `1e-3` voxel along the ray so a
165
+ * sample on a cell face is never skipped by rounding.
166
+ */
167
+ export function vdbFrameSkipEmpty(image, o, d, t0, t1, cutoff, dilate, maxCells = 64) {
168
+ const h = hddaInit(o, t0, d, t1, 8);
169
+ const back = f(1e-3 / Math.max(Math.hypot(d[0], d[1], d[2]), 1e-6));
170
+ let ts = t0;
171
+ for (let n = 0; n < maxCells; n++) {
172
+ const te = hddaCellEnd(h);
173
+ let b;
174
+ if (!dilate)
175
+ b = cellBoundTrilinear(image, h.voxel, 8);
176
+ else {
177
+ b = -Infinity;
178
+ for (let k = 0; k < 27; k++) {
179
+ const c = [h.voxel[0] + ((k % 3) - 1) * 8, h.voxel[1] + ((Math.floor(k / 3) % 3) - 1) * 8, h.voxel[2] + (Math.floor(k / 9) - 1) * 8];
180
+ b = Math.max(b, nodeMax(image, c, 8));
181
+ }
182
+ }
183
+ if (b > cutoff)
184
+ return [Math.max(t0, f(ts - back)), te];
185
+ ts = te;
186
+ if (!hddaStep(h))
187
+ return [t1, t1];
188
+ }
189
+ return [Math.max(t0, f(ts - back)), Math.max(t0, f(ts - back))];
190
+ }
191
+ //# sourceMappingURL=sparse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sparse.js","sourceRoot":"","sources":["../../../src/tools/frame/sparse.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,mGAAmG;AACnG,6DAA6D;AAC7D,4GAA4G;AAC5G,iGAAiG;AACjG,iGAAiG;AACjG,2BAA2B;AAE3B;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,SAAS,EAAa,MAAM,iBAAiB,CAAC;AACzJ,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,mBAAmB,IAAI,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEjH,OAAO,EAAE,mBAAmB,EAAE,CAAC;AAE/B,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;AAUtB;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,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 2x2x2 box downsample with\n// clamped edge taps, the mip atlas layout), as float data.\n// Copyright (c) mjurczyk/openvdb contributors. Licensed under the MIT License (see THIRD_PARTY_NOTICES.md).\n// Changes: f32 data without the 8-bit rounding; the first level comes from a sparse grid through\n// `vdbResampleGrid` (box); node-average sampling and the HDDA skip are ours (K3.2). Divergences:\n// DIVERGES.md (K3.2 rows).\n\n/**\n * CPU side of the sparse volume source's LOD strategies (K3.2, R1 §4.3) and the CPU twins of its\n * WGSL (`@pmndrs/vdb/three` `sparse-source.ts`):\n *\n * - `'coarse-pyramid'`: {@link vdbBoxPyramid} builds the dense coarse levels his\n * `sampleExtinction(localPos, lod)` reads at lod ≥ 1. The base level L₀ = max(1, ⌈log2(maxTexels /\n * pyramidMax)⌉) is a box resample of the sparse grid (`vdbResampleGrid`, filter `'box'`) to\n * ⌈texels / 2^L₀⌉ voxels over the exact index box, so texel j is centred at uvw (j + 0.5) / dims as\n * his mip levels are; the levels above it are his 2x2x2 box mip atlas, in float\n * ({@link vdbBoxMipAtlasF32}).\n * - `'node-average'`: {@link vdbFrameNodeAverageSample} is the twin of the trilinear interpolation\n * of `vdbNodeAverage` over the leaf (dim 8) or lower-node (dim 128) lattice.\n * - HDDA skip: {@link vdbFrameSkipEmpty} is the twin of the shadow march's empty-space query.\n *\n * Engine-free and core-free (D20): reads the NanoVDB image with the `tools/cpu` twins.\n */\n\nimport { VDBToolsError } from \"../errors.js\";\nimport { cellBoundTrilinear, hddaCellEnd, hddaInit, hddaStep, indexBBox, leafVoxels, nodeAverage, nodeMax, treeNodes, type Vec3 } from \"../cpu/march.js\";\nimport { vdbResampleGrid } from \"../nanovdb/resample.js\";\nimport { GRID_OFF_MAP, MAP_OFF_MATD, MAP_OFF_VECD } from \"../nanovdb/bytes.js\";\nimport { vdbBoxPyramidLayout, vdbPyramidBaseLevel, vdbPyramidLevelSize as levelSize } from \"./pyramid-layout.js\";\n\nexport { vdbPyramidBaseLevel };\n\nconst f = Math.fround;\n\n/** A float mip atlas in his layout: levels 1..n side by side on x. */\nexport interface VDBFloatMipAtlas {\n readonly data: Float32Array;\n readonly dimensions: [number, number, number];\n /** Levels in the atlas (above the base). */\n readonly levels: number;\n}\n\n/**\n * His box mip atlas (frameMipmaps.js `buildAtlas` / `packAtlas` / `downsample`) over float data:\n * levels 1..n with n = ⌈log2(max side)⌉, each the 2x2x2 mean of the level below with edge taps\n * clamped; level l at x = atlasWidth − atlasWidth / 2^(l−1). No 8-bit rounding. Null for a 1³ base.\n */\nexport function vdbBoxMipAtlasF32(data: Float32Array, dimensions: readonly number[]): VDBFloatMipAtlas | null {\n const [width, height, depth] = dimensions as Vec3;\n const count = Math.ceil(Math.log2(Math.max(width, height, depth, 1)));\n if (count < 1) return null;\n const levels: { data: Float32Array; width: number; height: number; depth: number }[] = [];\n let level = { data, width, height, depth };\n for (let index = 1; index <= count; index++) {\n const tw = levelSize(level.width, 1);\n const th = levelSize(level.height, 1);\n const td = levelSize(level.depth, 1);\n const out = new Float32Array(tw * th * td);\n const src = level;\n for (let z = 0; z < td; z++) {\n const z0 = Math.min(z * 2, src.depth - 1);\n const z1 = Math.min(z * 2 + 1, src.depth - 1);\n for (let y = 0; y < th; y++) {\n const y0 = Math.min(y * 2, src.height - 1);\n const y1 = Math.min(y * 2 + 1, src.height - 1);\n const r00 = (y0 + z0 * src.height) * src.width;\n const r10 = (y1 + z0 * src.height) * src.width;\n const r01 = (y0 + z1 * src.height) * src.width;\n const r11 = (y1 + z1 * src.height) * src.width;\n for (let x = 0; x < tw; x++) {\n const x0 = Math.min(x * 2, src.width - 1);\n const x1 = Math.min(x * 2 + 1, src.width - 1);\n const d = src.data;\n out[x + (y + z * th) * tw] =\n (d[x0 + r00]! + d[x1 + r00]! + d[x0 + r10]! + d[x1 + r10]! + d[x0 + r01]! + d[x1 + r01]! + d[x0 + r11]! + d[x1 + r11]!) / 8;\n }\n }\n }\n level = { data: out, width: tw, height: th, depth: td };\n levels.push(level);\n }\n const atlasWidth = 2 ** Math.max(Math.ceil(Math.log2(width)), levels.length);\n const atlasHeight = levelSize(height, 1);\n const atlasDepth = levelSize(depth, 1);\n const atlas = new Float32Array(atlasWidth * atlasHeight * atlasDepth);\n levels.forEach((l, levelIndex) => {\n const offset = atlasWidth - atlasWidth / 2 ** levelIndex;\n for (let z = 0; z < l.depth; z++) {\n for (let y = 0; y < l.height; y++) {\n const row = (y + z * atlasHeight) * atlasWidth + offset;\n atlas.set(l.data.subarray((y + z * l.height) * l.width, (y + z * l.height + 1) * l.width), row);\n }\n }\n });\n return { data: atlas, dimensions: [atlasWidth, atlasHeight, atlasDepth], levels: levels.length };\n}\n\n/** Options of {@link vdbBoxPyramid}. */\nexport interface VDBBoxPyramidOptions {\n /** Inclusive voxel index box the volume's unit box covers. Default: the grid's index bbox. */\n indexBox?: { min: Vec3; max: Vec3 };\n /** Texels on the longest side of the base level at most (R1: `pyramidMax`, default 128). */\n pyramidMax?: number;\n /** Base level override (default {@link vdbPyramidBaseLevel}). */\n level?: number;\n}\n\n/** The dense coarse levels of a sparse grid (see the file comment). */\nexport interface VDBBoxPyramid {\n /** L₀: the level of `data` in level-0 voxels (texel footprint 2^L₀). */\n readonly level: number;\n /** Texels of the base level, ⌈indexBox size / 2^L₀⌉. */\n readonly dimensions: [number, number, number];\n /** Base level, x fastest, the box mean of the sparse grid over each texel's cell. */\n readonly data: Float32Array;\n /** Levels L₀+1… in his atlas layout (null when the base is 1³). */\n readonly atlas: VDBFloatMipAtlas | null;\n /** Total levels the source then has: L₀ + atlas levels. */\n readonly lodLevels: number;\n}\n\n/**\n * The coarse pyramid of a sparse FLOAT/Fp grid image (CPU, `vdbResampleGrid` box). The grid's Map must\n * be axis-aligned (vdbResampleGrid's rule).\n */\nexport function vdbBoxPyramid(image: Uint32Array, o: VDBBoxPyramidOptions = {}): VDBBoxPyramid {\n const box = o.indexBox ?? indexBBox(image);\n const texels: Vec3 = [box.max[0] - box.min[0] + 1, box.max[1] - box.min[1] + 1, box.max[2] - box.min[2] + 1];\n if (texels.some((t) => !(t > 0))) throw new VDBToolsError(\"VDB_BAD_OPTION\", \"vdbBoxPyramid: empty index box\");\n const layout = vdbBoxPyramidLayout(texels, { ...(o.pyramidMax !== undefined ? { pyramidMax: o.pyramidMax } : {}), ...(o.level !== undefined ? { level: o.level } : {}) });\n const level = layout.level;\n const dims: Vec3 = [...layout.dimensions];\n // The index cell box [min − ½, max + ½] in world (NanoVDB: world = matd · ijk + vecd).\n const view = new DataView(image.buffer, image.byteOffset, image.byteLength);\n const mat = Array.from({ length: 9 }, (_, i) => view.getFloat64(GRID_OFF_MAP + MAP_OFF_MATD + i * 8, true));\n const vec = Array.from({ length: 3 }, (_, i) => view.getFloat64(GRID_OFF_MAP + MAP_OFF_VECD + i * 8, true));\n const world = (ijk: Vec3): Vec3 => [0, 1, 2].map((r) => mat[r * 3]! * ijk[0] + mat[r * 3 + 1]! * ijk[1] + mat[r * 3 + 2]! * ijk[2] + vec[r]!) as Vec3;\n const lo = world([box.min[0] - 0.5, box.min[1] - 0.5, box.min[2] - 0.5]);\n const hi = world([box.max[0] + 0.5, box.max[1] + 0.5, box.max[2] + 0.5]);\n const coarse = vdbResampleGrid(image, { filter: \"box\", dimensions: dims, bbox: [lo, hi] });\n // Dense readout of the resampled grid (index box [0, dims − 1]); voxels outside its leaves and tiles are background.\n const data = new Float32Array(dims[0] * dims[1] * dims[2]);\n const background = 0;\n if (background !== 0) data.fill(background);\n const put = (x: number, y: number, z: number, v: number) => {\n if (x < 0 || y < 0 || z < 0 || x >= dims[0] || y >= dims[1] || z >= dims[2]) return;\n data[x + (y + z * dims[1]) * dims[0]] = v;\n };\n for (const node of treeNodes(coarse.image)) {\n for (const t of node.activeTiles) {\n for (let z = 0; z < t.dim; z++) for (let y = 0; y < t.dim; y++) for (let x = 0; x < t.dim; x++) put(t.origin[0] + x, t.origin[1] + y, t.origin[2] + z, t.value);\n }\n if (node.level !== 0) continue;\n const { values } = leafVoxels(coarse.image, node.address);\n const [ox, oy, oz] = node.origin;\n for (let n = 0; n < 512; n++) put(ox + (n >> 6), oy + ((n >> 3) & 7), oz + (n & 7), values[n]!);\n }\n const atlas = vdbBoxMipAtlasF32(data, dims);\n return { level, dimensions: dims, data, atlas, lodLevels: level + (atlas?.levels ?? 0) };\n}\n\n/**\n * Twin of the sparse source's node-average tap (`vdbFrameNodeAverage` in `three/sparse-source.ts`):\n * trilinear interpolation of {@link nodeAverage} over the lattice of aligned `dim`-cells, whose\n * centres are at `dim·j + dim/2 − ½` in index space (voxel centres at integers). `p` is in index\n * space. f32 arithmetic in WGSL order.\n */\nexport function vdbFrameNodeAverageSample(image: Uint32Array, p: Vec3, dim: number): number {\n const fd = f(dim);\n const half = f(f(0.5 * fd) - 0.5);\n const q = p.map((v) => f(f(v - half) / fd)) as Vec3;\n const base = q.map(Math.floor) as Vec3;\n const w = q.map((v, i) => f(v - base[i]!)) as Vec3;\n const c: Vec3 = [base[0] * dim, base[1] * dim, base[2] * dim];\n const v: number[] = [];\n for (let k = 0; k < 8; k++) v.push(nodeAverage(image, [c[0] + (k & 1) * dim, c[1] + ((k >> 1) & 1) * dim, c[2] + ((k >> 2) & 1) * dim], dim));\n const mix = (a: number, b: number, t: number) => f(a + f(t * f(b - a)));\n const x00 = mix(v[0]!, v[1]!, w[0]);\n const x10 = mix(v[2]!, v[3]!, w[0]);\n const x01 = mix(v[4]!, v[5]!, w[0]);\n const x11 = mix(v[6]!, v[7]!, w[0]);\n return mix(mix(x00, x10, w[1]), mix(x01, x11, w[1]), w[2]);\n}\n\n/**\n * Twin of the shadow march's empty-space query (`vdbFrameSkipEmpty`, K3.2): an HDDA over 8³ cells\n * of the ray `o + d·t` (sample space: index space, the trilinear base voxel is `floor(p)`) from `t0`\n * to `t1`. Returns `[ts, te]`: every sample with `t < ts` reads only voxels whose bound is ≤ `cutoff`\n * (so it is skipped exactly), and the cell from `ts` to `te` must be sampled; `[t1, t1]` when the\n * rest is empty. The bound per cell is `cellBoundTrilinear` (the 2x2x2 block a level-0 trilinear tap\n * reads) or, with `dilate`, the max of `nodeMax` over the 3x3x3 cells around (taps of the coarse\n * levels that reach at most 8 voxels past the cell). After `maxCells` empty cells it returns\n * `[ts, ts]` (the caller asks again from there). `ts` steps back by `1e-3` voxel along the ray so a\n * sample on a cell face is never skipped by rounding.\n */\nexport function vdbFrameSkipEmpty(image: Uint32Array, o: Vec3, d: Vec3, t0: number, t1: number, cutoff: number, dilate: boolean, maxCells = 64): [number, number] {\n const h = hddaInit(o, t0, d, t1, 8);\n const back = f(1e-3 / Math.max(Math.hypot(d[0], d[1], d[2]), 1e-6));\n let ts = t0;\n for (let n = 0; n < maxCells; n++) {\n const te = hddaCellEnd(h);\n let b: number;\n if (!dilate) b = cellBoundTrilinear(image, h.voxel, 8);\n else {\n b = -Infinity;\n for (let k = 0; k < 27; k++) {\n const c: Vec3 = [h.voxel[0] + ((k % 3) - 1) * 8, h.voxel[1] + ((Math.floor(k / 3) % 3) - 1) * 8, h.voxel[2] + (Math.floor(k / 9) - 1) * 8];\n b = Math.max(b, nodeMax(image, c, 8));\n }\n }\n if (b > cutoff) return [Math.max(t0, f(ts - back)), te];\n ts = te;\n if (!hddaStep(h)) return [t1, t1];\n }\n return [Math.max(t0, f(ts - back)), Math.max(t0, f(ts - back))];\n}\n"]}