@pmndrs/vdb 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (576) hide show
  1. package/CHANGELOG.md +592 -2
  2. package/README.md +85 -37
  3. package/THIRD_PARTY_NOTICES.md +197 -29
  4. package/dist/core/compute/atlas.d.ts +10 -2
  5. package/dist/core/compute/atlas.js +6 -1
  6. package/dist/core/compute/atlas.js.map +1 -1
  7. package/dist/core/compute/index.d.ts +3 -3
  8. package/dist/core/compute/index.js +2 -2
  9. package/dist/core/compute/index.js.map +1 -1
  10. package/dist/core/compute/majorant-build.d.ts +45 -0
  11. package/dist/core/compute/majorant-build.js +193 -0
  12. package/dist/core/compute/majorant-build.js.map +1 -0
  13. package/dist/core/compute/multi-scale.d.ts +155 -0
  14. package/dist/core/compute/multi-scale.js +684 -0
  15. package/dist/core/compute/multi-scale.js.map +1 -0
  16. package/dist/core/compute/pyramid.d.ts +22 -7
  17. package/dist/core/compute/pyramid.js +22 -9
  18. package/dist/core/compute/pyramid.js.map +1 -1
  19. package/dist/core/compute/shared.d.ts +1 -0
  20. package/dist/core/compute/shared.js.map +1 -1
  21. package/dist/core/compute/stats.d.ts +10 -3
  22. package/dist/core/compute/stats.js +6 -1
  23. package/dist/core/compute/stats.js.map +1 -1
  24. package/dist/core/compute/value-transform.d.ts +8 -1
  25. package/dist/core/compute/value-transform.js +9 -3
  26. package/dist/core/compute/value-transform.js.map +1 -1
  27. package/dist/core/errors.d.ts +10 -0
  28. package/dist/core/errors.js +8 -0
  29. package/dist/core/errors.js.map +1 -1
  30. package/dist/core/frame/emission.d.ts +85 -0
  31. package/dist/core/frame/emission.js +422 -0
  32. package/dist/core/frame/emission.js.map +1 -0
  33. package/dist/core/frame/environment.d.ts +47 -0
  34. package/dist/core/frame/environment.js +178 -0
  35. package/dist/core/frame/environment.js.map +1 -0
  36. package/dist/core/frame/index.d.ts +39 -0
  37. package/dist/core/frame/index.js +27 -0
  38. package/dist/core/frame/index.js.map +1 -0
  39. package/dist/core/frame/kernels.d.ts +115 -0
  40. package/dist/core/frame/kernels.js +496 -0
  41. package/dist/core/frame/kernels.js.map +1 -0
  42. package/dist/core/frame/limits.d.ts +67 -0
  43. package/dist/core/frame/limits.js +109 -0
  44. package/dist/core/frame/limits.js.map +1 -0
  45. package/dist/core/frame/phase.d.ts +17 -0
  46. package/dist/core/frame/phase.js +53 -0
  47. package/dist/core/frame/phase.js.map +1 -0
  48. package/dist/core/frame/pipelines.d.ts +49 -0
  49. package/dist/core/frame/pipelines.js +147 -0
  50. package/dist/core/frame/pipelines.js.map +1 -0
  51. package/dist/core/frame/renderer.d.ts +122 -0
  52. package/dist/core/frame/renderer.js +1712 -0
  53. package/dist/core/frame/renderer.js.map +1 -0
  54. package/dist/core/frame/resources.d.ts +71 -0
  55. package/dist/core/frame/resources.js +100 -0
  56. package/dist/core/frame/resources.js.map +1 -0
  57. package/dist/core/frame/scattering.d.ts +97 -0
  58. package/dist/core/frame/scattering.js +332 -0
  59. package/dist/core/frame/scattering.js.map +1 -0
  60. package/dist/core/frame/settings.d.ts +243 -0
  61. package/dist/core/frame/settings.js +67 -0
  62. package/dist/core/frame/settings.js.map +1 -0
  63. package/dist/core/frame/shadows.d.ts +55 -0
  64. package/dist/core/frame/shadows.js +460 -0
  65. package/dist/core/frame/shadows.js.map +1 -0
  66. package/dist/core/frame/types.d.ts +415 -0
  67. package/dist/core/frame/types.js +49 -0
  68. package/dist/core/frame/types.js.map +1 -0
  69. package/dist/core/frame/uniforms.d.ts +105 -0
  70. package/dist/core/frame/uniforms.js +276 -0
  71. package/dist/core/frame/uniforms.js.map +1 -0
  72. package/dist/core/frame/wgsl/chunks.d.ts +4 -0
  73. package/dist/core/frame/wgsl/chunks.js +728 -0
  74. package/dist/core/frame/wgsl/chunks.js.map +1 -0
  75. package/dist/core/frame/wgsl/emission.d.ts +82 -0
  76. package/dist/core/frame/wgsl/emission.js +353 -0
  77. package/dist/core/frame/wgsl/emission.js.map +1 -0
  78. package/dist/core/frame/wgsl/environment.d.ts +42 -0
  79. package/dist/core/frame/wgsl/environment.js +711 -0
  80. package/dist/core/frame/wgsl/environment.js.map +1 -0
  81. package/dist/core/frame/wgsl/gather.d.ts +55 -0
  82. package/dist/core/frame/wgsl/gather.js +850 -0
  83. package/dist/core/frame/wgsl/gather.js.map +1 -0
  84. package/dist/core/frame/wgsl/integrate.d.ts +78 -0
  85. package/dist/core/frame/wgsl/integrate.js +213 -0
  86. package/dist/core/frame/wgsl/integrate.js.map +1 -0
  87. package/dist/core/frame/wgsl/lighting.d.ts +103 -0
  88. package/dist/core/frame/wgsl/lighting.js +1636 -0
  89. package/dist/core/frame/wgsl/lighting.js.map +1 -0
  90. package/dist/core/frame/wgsl/occluders.d.ts +20 -0
  91. package/dist/core/frame/wgsl/occluders.js +95 -0
  92. package/dist/core/frame/wgsl/occluders.js.map +1 -0
  93. package/dist/core/frame/wgsl/resolve.d.ts +19 -0
  94. package/dist/core/frame/wgsl/resolve.js +205 -0
  95. package/dist/core/frame/wgsl/resolve.js.map +1 -0
  96. package/dist/core/frame/wgsl/shadows.d.ts +35 -0
  97. package/dist/core/frame/wgsl/shadows.js +328 -0
  98. package/dist/core/frame/wgsl/shadows.js.map +1 -0
  99. package/dist/core/half.d.ts +11 -0
  100. package/dist/core/half.js +22 -0
  101. package/dist/core/half.js.map +1 -0
  102. package/dist/core/index.d.ts +25 -3
  103. package/dist/core/index.js +23 -4
  104. package/dist/core/index.js.map +1 -1
  105. package/dist/core/internal.d.ts +17 -1
  106. package/dist/core/internal.js +18 -1
  107. package/dist/core/internal.js.map +1 -1
  108. package/dist/core/pool/image-header.d.ts +13 -2
  109. package/dist/core/pool/image-header.js +24 -5
  110. package/dist/core/pool/image-header.js.map +1 -1
  111. package/dist/core/pool/layout.d.ts +35 -1
  112. package/dist/core/pool/layout.js +51 -2
  113. package/dist/core/pool/layout.js.map +1 -1
  114. package/dist/core/pool/limits.d.ts +1 -0
  115. package/dist/core/pool/limits.js +1 -0
  116. package/dist/core/pool/limits.js.map +1 -1
  117. package/dist/core/pool/pool.d.ts +120 -15
  118. package/dist/core/pool/pool.js +255 -24
  119. package/dist/core/pool/pool.js.map +1 -1
  120. package/dist/core/reference/index.d.ts +6 -0
  121. package/dist/core/reference/index.js +7 -0
  122. package/dist/core/reference/index.js.map +1 -0
  123. package/dist/core/reference/renderer.d.ts +105 -0
  124. package/dist/core/reference/renderer.js +474 -0
  125. package/dist/core/reference/renderer.js.map +1 -0
  126. package/dist/core/reference/wgsl.d.ts +65 -0
  127. package/dist/core/reference/wgsl.js +803 -0
  128. package/dist/core/reference/wgsl.js.map +1 -0
  129. package/dist/{three → core}/sequence.d.ts +32 -2
  130. package/dist/{three → core}/sequence.js +24 -2
  131. package/dist/core/sequence.js.map +1 -0
  132. package/dist/core/source/brick-cache.d.ts +165 -0
  133. package/dist/core/source/brick-cache.js +627 -0
  134. package/dist/core/source/brick-cache.js.map +1 -0
  135. package/dist/core/source/dense-fill.d.ts +53 -0
  136. package/dist/core/source/dense-fill.js +377 -0
  137. package/dist/core/source/dense-fill.js.map +1 -0
  138. package/dist/core/source/dense.d.ts +33 -2
  139. package/dist/core/source/dense.js +121 -24
  140. package/dist/core/source/dense.js.map +1 -1
  141. package/dist/core/source/sparse-wgsl.d.ts +92 -0
  142. package/dist/core/source/sparse-wgsl.js +481 -0
  143. package/dist/core/source/sparse-wgsl.js.map +1 -0
  144. package/dist/core/source/sparse.d.ts +192 -0
  145. package/dist/core/source/sparse.js +762 -0
  146. package/dist/core/source/sparse.js.map +1 -0
  147. package/dist/core/source/types.d.ts +59 -2
  148. package/dist/core/source/types.js.map +1 -1
  149. package/dist/core/surface/index.d.ts +10 -0
  150. package/dist/core/surface/index.js +9 -0
  151. package/dist/core/surface/index.js.map +1 -0
  152. package/dist/core/surface/level-set-pass.d.ts +140 -0
  153. package/dist/core/surface/level-set-pass.js +291 -0
  154. package/dist/core/surface/level-set-pass.js.map +1 -0
  155. package/dist/core/surface/level-set-wgsl.d.ts +46 -0
  156. package/dist/core/surface/level-set-wgsl.js +99 -0
  157. package/dist/core/surface/level-set-wgsl.js.map +1 -0
  158. package/dist/core/surface/points.d.ts +109 -0
  159. package/dist/core/surface/points.js +226 -0
  160. package/dist/core/surface/points.js.map +1 -0
  161. package/dist/core/types.d.ts +12 -3
  162. package/dist/core/types.js +6 -2
  163. package/dist/core/types.js.map +1 -1
  164. package/dist/core/wgsl/api.d.ts +29 -5
  165. package/dist/core/wgsl/api.js +110 -27
  166. package/dist/core/wgsl/api.js.map +1 -1
  167. package/dist/core/wgsl/generate.d.ts +8 -0
  168. package/dist/core/wgsl/generate.js +195 -22
  169. package/dist/core/wgsl/generate.js.map +1 -1
  170. package/dist/core/wgsl/lean.d.ts +50 -0
  171. package/dist/core/wgsl/lean.js +327 -0
  172. package/dist/core/wgsl/lean.js.map +1 -0
  173. package/dist/core/wgsl/level-set.d.ts +5 -1
  174. package/dist/core/wgsl/level-set.js +11 -5
  175. package/dist/core/wgsl/level-set.js.map +1 -1
  176. package/dist/core/wgsl/majorant.d.ts +62 -0
  177. package/dist/core/wgsl/majorant.js +381 -0
  178. package/dist/core/wgsl/majorant.js.map +1 -0
  179. package/dist/core/wgsl/pnanovdb.chunks.generated.d.ts +2 -2
  180. package/dist/core/wgsl/pnanovdb.chunks.generated.js +15 -12
  181. package/dist/core/wgsl/pnanovdb.chunks.generated.js.map +1 -1
  182. package/dist/core/wgsl/types.d.ts +97 -3
  183. package/dist/core/wgsl/types.js.map +1 -1
  184. package/dist/three/coarse-first.d.ts +53 -8
  185. package/dist/three/coarse-first.js +24 -6
  186. package/dist/three/coarse-first.js.map +1 -1
  187. package/dist/three/compute.d.ts +12 -2
  188. package/dist/three/compute.js +16 -6
  189. package/dist/three/compute.js.map +1 -1
  190. package/dist/three/device.d.ts +7 -0
  191. package/dist/three/device.js +3 -0
  192. package/dist/three/device.js.map +1 -1
  193. package/dist/three/frame/core-environment.d.ts +38 -0
  194. package/dist/three/frame/core-environment.js +154 -0
  195. package/dist/three/frame/core-environment.js.map +1 -0
  196. package/dist/three/frame/core-integrate-material.d.ts +34 -0
  197. package/dist/three/frame/core-integrate-material.js +162 -0
  198. package/dist/three/frame/core-integrate-material.js.map +1 -0
  199. package/dist/three/frame/core-occluders.d.ts +53 -0
  200. package/dist/three/frame/core-occluders.js +193 -0
  201. package/dist/three/frame/core-occluders.js.map +1 -0
  202. package/dist/three/frame/core-structs.d.ts +34 -0
  203. package/dist/three/frame/core-structs.js +61 -0
  204. package/dist/three/frame/core-structs.js.map +1 -0
  205. package/dist/three/frame/core-textures.d.ts +41 -0
  206. package/dist/three/frame/core-textures.js +114 -0
  207. package/dist/three/frame/core-textures.js.map +1 -0
  208. package/dist/three/frame/emission-light.d.ts +64 -114
  209. package/dist/three/frame/emission-light.js +188 -567
  210. package/dist/three/frame/emission-light.js.map +1 -1
  211. package/dist/three/frame/index.d.ts +11 -31
  212. package/dist/three/frame/index.js +9 -29
  213. package/dist/three/frame/index.js.map +1 -1
  214. package/dist/three/frame/medium.d.ts +12 -0
  215. package/dist/three/frame/medium.js.map +1 -1
  216. package/dist/three/frame/renderer.d.ts +58 -454
  217. package/dist/three/frame/renderer.js +409 -1427
  218. package/dist/three/frame/renderer.js.map +1 -1
  219. package/dist/three/frame/spectrum.d.ts +0 -14
  220. package/dist/three/frame/spectrum.js +2 -23
  221. package/dist/three/frame/spectrum.js.map +1 -1
  222. package/dist/three/frame/three-internals.d.ts +3 -8
  223. package/dist/three/frame/three-internals.js +13 -11
  224. package/dist/three/frame/three-internals.js.map +1 -1
  225. package/dist/three/frame/volume-shadows.d.ts +93 -107
  226. package/dist/three/frame/volume-shadows.js +278 -631
  227. package/dist/three/frame/volume-shadows.js.map +1 -1
  228. package/dist/three/frame/volume.d.ts +91 -33
  229. package/dist/three/frame/volume.js +63 -51
  230. package/dist/three/frame/volume.js.map +1 -1
  231. package/dist/three/grid-node.d.ts +34 -1
  232. package/dist/three/grid-node.js +36 -1
  233. package/dist/three/grid-node.js.map +1 -1
  234. package/dist/three/index.d.ts +20 -11
  235. package/dist/three/index.js +21 -12
  236. package/dist/three/index.js.map +1 -1
  237. package/dist/three/internal.d.ts +14 -8
  238. package/dist/three/internal.js +11 -7
  239. package/dist/three/internal.js.map +1 -1
  240. package/dist/three/level-set-material.d.ts +81 -8
  241. package/dist/three/level-set-material.js +162 -125
  242. package/dist/three/level-set-material.js.map +1 -1
  243. package/dist/three/level-set-physical-material.d.ts +154 -0
  244. package/dist/three/level-set-physical-material.js +253 -0
  245. package/dist/three/level-set-physical-material.js.map +1 -0
  246. package/dist/three/level-set-velocity.d.ts +94 -0
  247. package/dist/three/level-set-velocity.js +208 -0
  248. package/dist/three/level-set-velocity.js.map +1 -0
  249. package/dist/three/material.d.ts +141 -11
  250. package/dist/three/material.js +161 -18
  251. package/dist/three/material.js.map +1 -1
  252. package/dist/three/points.d.ts +60 -4
  253. package/dist/three/points.js +140 -9
  254. package/dist/three/points.js.map +1 -1
  255. package/dist/three/sparse-source.d.ts +49 -117
  256. package/dist/three/sparse-source.js +109 -580
  257. package/dist/three/sparse-source.js.map +1 -1
  258. package/dist/three/volume-source.d.ts +11 -156
  259. package/dist/three/volume-source.js +29 -272
  260. package/dist/three/volume-source.js.map +1 -1
  261. package/dist/tools/cpu/brick-atlas.d.ts +36 -0
  262. package/dist/tools/cpu/brick-atlas.js +129 -0
  263. package/dist/tools/cpu/brick-atlas.js.map +1 -0
  264. package/dist/tools/cpu/compute.d.ts +23 -4
  265. package/dist/tools/cpu/compute.js +35 -14
  266. package/dist/tools/cpu/compute.js.map +1 -1
  267. package/dist/tools/cpu/lean-reads.d.ts +81 -0
  268. package/dist/tools/cpu/lean-reads.js +262 -0
  269. package/dist/tools/cpu/lean-reads.js.map +1 -0
  270. package/dist/tools/cpu/level-set.d.ts +42 -3
  271. package/dist/tools/cpu/level-set.js +59 -7
  272. package/dist/tools/cpu/level-set.js.map +1 -1
  273. package/dist/tools/cpu/majorant.d.ts +265 -0
  274. package/dist/tools/cpu/majorant.js +541 -0
  275. package/dist/tools/cpu/majorant.js.map +1 -0
  276. package/dist/tools/cpu/march.d.ts +93 -2
  277. package/dist/tools/cpu/march.js +165 -14
  278. package/dist/tools/cpu/march.js.map +1 -1
  279. package/dist/tools/cpu/mesh-decimate.d.ts +124 -0
  280. package/dist/tools/cpu/mesh-decimate.js +1225 -0
  281. package/dist/tools/cpu/mesh-decimate.js.map +1 -0
  282. package/dist/tools/cpu/points.d.ts +29 -0
  283. package/dist/tools/cpu/points.js +38 -0
  284. package/dist/tools/cpu/points.js.map +1 -0
  285. package/dist/tools/cpu/read-value.d.ts +19 -6
  286. package/dist/tools/cpu/read-value.js +32 -17
  287. package/dist/tools/cpu/read-value.js.map +1 -1
  288. package/dist/tools/cpu/sample-trilinear.d.ts +17 -4
  289. package/dist/tools/cpu/sample-trilinear.js +19 -7
  290. package/dist/tools/cpu/sample-trilinear.js.map +1 -1
  291. package/dist/tools/cpu/stride-tables.d.ts +2 -2
  292. package/dist/tools/cpu/stride-tables.generated.d.ts +6 -5
  293. package/dist/tools/cpu/stride-tables.generated.js +7 -6
  294. package/dist/tools/cpu/stride-tables.generated.js.map +1 -1
  295. package/dist/tools/cpu/stride-tables.js +1 -1
  296. package/dist/tools/cpu/stride-tables.js.map +1 -1
  297. package/dist/tools/cpu/surface-nets.d.ts +90 -0
  298. package/dist/tools/cpu/surface-nets.js +597 -0
  299. package/dist/tools/cpu/surface-nets.js.map +1 -0
  300. package/dist/tools/errors.d.ts +9 -0
  301. package/dist/tools/errors.js +9 -0
  302. package/dist/tools/errors.js.map +1 -1
  303. package/dist/tools/frame/ambient.d.ts +98 -0
  304. package/dist/tools/frame/ambient.js +274 -0
  305. package/dist/tools/frame/ambient.js.map +1 -0
  306. package/dist/tools/frame/blackbody.d.ts +15 -0
  307. package/dist/tools/frame/blackbody.js +35 -0
  308. package/dist/tools/frame/blackbody.js.map +1 -1
  309. package/dist/tools/frame/brick-cache.d.ts +165 -0
  310. package/dist/tools/frame/brick-cache.js +326 -0
  311. package/dist/tools/frame/brick-cache.js.map +1 -0
  312. package/dist/tools/frame/emission.d.ts +9 -0
  313. package/dist/tools/frame/emission.js +9 -1
  314. package/dist/tools/frame/emission.js.map +1 -1
  315. package/dist/tools/frame/environment-gpu.d.ts +111 -0
  316. package/dist/tools/frame/environment-gpu.js +280 -0
  317. package/dist/tools/frame/environment-gpu.js.map +1 -0
  318. package/dist/tools/frame/environment.d.ts +3 -2
  319. package/dist/tools/frame/environment.js +8 -4
  320. package/dist/tools/frame/environment.js.map +1 -1
  321. package/dist/tools/frame/froxel.d.ts +58 -0
  322. package/dist/tools/frame/froxel.js +115 -0
  323. package/dist/tools/frame/froxel.js.map +1 -0
  324. package/dist/tools/frame/grid.d.ts +90 -0
  325. package/dist/tools/frame/grid.js +112 -13
  326. package/dist/tools/frame/grid.js.map +1 -1
  327. package/dist/tools/frame/index.d.ts +14 -0
  328. package/dist/tools/frame/index.js +45 -4
  329. package/dist/tools/frame/index.js.map +1 -1
  330. package/dist/tools/frame/medium.d.ts +16 -0
  331. package/dist/tools/frame/medium.js +3 -1
  332. package/dist/tools/frame/medium.js.map +1 -1
  333. package/dist/tools/frame/mie.d.ts +9 -0
  334. package/dist/tools/frame/mie.js +18 -0
  335. package/dist/tools/frame/mie.js.map +1 -1
  336. package/dist/tools/frame/mlp-nn.d.ts +36 -0
  337. package/dist/tools/frame/mlp-nn.js +159 -0
  338. package/dist/tools/frame/mlp-nn.js.map +1 -0
  339. package/dist/tools/frame/mlp-tza.d.ts +29 -0
  340. package/dist/tools/frame/mlp-tza.js +186 -0
  341. package/dist/tools/frame/mlp-tza.js.map +1 -0
  342. package/dist/tools/frame/mlp.d.ts +183 -0
  343. package/dist/tools/frame/mlp.js +434 -0
  344. package/dist/tools/frame/mlp.js.map +1 -0
  345. package/dist/tools/frame/ms-exit.d.ts +42 -0
  346. package/dist/tools/frame/ms-exit.js +90 -0
  347. package/dist/tools/frame/ms-exit.js.map +1 -0
  348. package/dist/tools/frame/multi-scale.d.ts +152 -0
  349. package/dist/tools/frame/multi-scale.js +302 -0
  350. package/dist/tools/frame/multi-scale.js.map +1 -0
  351. package/dist/tools/frame/neural-weights.d.ts +6 -5
  352. package/dist/tools/frame/neural-weights.js +234 -235
  353. package/dist/tools/frame/neural-weights.js.map +1 -1
  354. package/dist/tools/frame/neural.js +1 -1
  355. package/dist/tools/frame/neural.js.map +1 -1
  356. package/dist/tools/frame/occluders.d.ts +51 -0
  357. package/dist/tools/frame/occluders.js +72 -0
  358. package/dist/tools/frame/occluders.js.map +1 -0
  359. package/dist/tools/frame/pyramid-layout.d.ts +17 -0
  360. package/dist/tools/frame/pyramid-layout.js +47 -0
  361. package/dist/tools/frame/pyramid-layout.js.map +1 -1
  362. package/dist/tools/frame/shadows.d.ts +110 -0
  363. package/dist/tools/frame/shadows.js +286 -0
  364. package/dist/tools/frame/shadows.js.map +1 -1
  365. package/dist/tools/frame/sparse.d.ts +82 -0
  366. package/dist/tools/frame/sparse.js +242 -1
  367. package/dist/tools/frame/sparse.js.map +1 -1
  368. package/dist/tools/frame/spectral-stack.d.ts +159 -0
  369. package/dist/tools/frame/spectral-stack.js +391 -0
  370. package/dist/tools/frame/spectral-stack.js.map +1 -0
  371. package/dist/tools/frame/spectral.d.ts +21 -2
  372. package/dist/tools/frame/spectral.js +30 -8
  373. package/dist/tools/frame/spectral.js.map +1 -1
  374. package/dist/tools/frame/stack.d.ts +115 -0
  375. package/dist/tools/frame/stack.js +290 -0
  376. package/dist/tools/frame/stack.js.map +1 -0
  377. package/dist/tools/frame/view.d.ts +131 -0
  378. package/dist/tools/frame/view.js +337 -0
  379. package/dist/tools/frame/view.js.map +1 -0
  380. package/dist/tools/index.d.ts +66 -15
  381. package/dist/tools/index.js +55 -11
  382. package/dist/tools/index.js.map +1 -1
  383. package/dist/tools/internal.d.ts +58 -17
  384. package/dist/tools/internal.js +65 -11
  385. package/dist/tools/internal.js.map +1 -1
  386. package/dist/tools/nanovdb/build-from-vdb.d.ts +11 -2
  387. package/dist/tools/nanovdb/build-from-vdb.js +10 -2
  388. package/dist/tools/nanovdb/build-from-vdb.js.map +1 -1
  389. package/dist/tools/nanovdb/bytes.d.ts +17 -4
  390. package/dist/tools/nanovdb/bytes.js +46 -3
  391. package/dist/tools/nanovdb/bytes.js.map +1 -1
  392. package/dist/tools/nanovdb/coarse-first.d.ts +19 -3
  393. package/dist/tools/nanovdb/coarse-first.js +7 -1
  394. package/dist/tools/nanovdb/coarse-first.js.map +1 -1
  395. package/dist/tools/nanovdb/half.d.ts +22 -0
  396. package/dist/tools/nanovdb/half.js +73 -0
  397. package/dist/tools/nanovdb/half.js.map +1 -0
  398. package/dist/tools/nanovdb/index.d.ts +3 -1
  399. package/dist/tools/nanovdb/index.js +2 -1
  400. package/dist/tools/nanovdb/index.js.map +1 -1
  401. package/dist/tools/nanovdb/inspect.d.ts +10 -1
  402. package/dist/tools/nanovdb/inspect.js +8 -1
  403. package/dist/tools/nanovdb/inspect.js.map +1 -1
  404. package/dist/tools/nanovdb/leaf-codec.d.ts +35 -1
  405. package/dist/tools/nanovdb/leaf-codec.js +40 -4
  406. package/dist/tools/nanovdb/leaf-codec.js.map +1 -1
  407. package/dist/tools/nanovdb/quantize.d.ts +39 -10
  408. package/dist/tools/nanovdb/quantize.js +96 -44
  409. package/dist/tools/nanovdb/quantize.js.map +1 -1
  410. package/dist/tools/nanovdb/resample.d.ts +20 -3
  411. package/dist/tools/nanovdb/resample.js +20 -7
  412. package/dist/tools/nanovdb/resample.js.map +1 -1
  413. package/dist/tools/nanovdb/serialize.d.ts +34 -3
  414. package/dist/tools/nanovdb/serialize.js +51 -7
  415. package/dist/tools/nanovdb/serialize.js.map +1 -1
  416. package/dist/tools/nanovdb/stats.d.ts +34 -5
  417. package/dist/tools/nanovdb/stats.js +87 -11
  418. package/dist/tools/nanovdb/stats.js.map +1 -1
  419. package/dist/tools/nanovdb/transform.d.ts +4 -0
  420. package/dist/tools/nanovdb/transform.js +3 -0
  421. package/dist/tools/nanovdb/transform.js.map +1 -1
  422. package/dist/tools/nanovdb/tree.d.ts +14 -3
  423. package/dist/tools/nanovdb/tree.js +25 -13
  424. package/dist/tools/nanovdb/tree.js.map +1 -1
  425. package/dist/tools/nanovdb/write-nvdb.d.ts +47 -12
  426. package/dist/tools/nanovdb/write-nvdb.js +108 -28
  427. package/dist/tools/nanovdb/write-nvdb.js.map +1 -1
  428. package/dist/tools/nvdb-file.d.ts +77 -7
  429. package/dist/tools/nvdb-file.js +177 -20
  430. package/dist/tools/nvdb-file.js.map +1 -1
  431. package/dist/tools/nvdb-stream.d.ts +23 -7
  432. package/dist/tools/nvdb-stream.js +78 -34
  433. package/dist/tools/nvdb-stream.js.map +1 -1
  434. package/dist/tools/reference/analytic.d.ts +41 -0
  435. package/dist/tools/reference/analytic.js +95 -0
  436. package/dist/tools/reference/analytic.js.map +1 -0
  437. package/dist/tools/reference/environment.d.ts +62 -0
  438. package/dist/tools/reference/environment.js +154 -0
  439. package/dist/tools/reference/environment.js.map +1 -0
  440. package/dist/tools/reference/index.d.ts +12 -0
  441. package/dist/tools/reference/index.js +13 -0
  442. package/dist/tools/reference/index.js.map +1 -0
  443. package/dist/tools/reference/media.d.ts +14 -0
  444. package/dist/tools/reference/media.js +30 -0
  445. package/dist/tools/reference/media.js.map +1 -0
  446. package/dist/tools/reference/rng.d.ts +20 -0
  447. package/dist/tools/reference/rng.js +30 -0
  448. package/dist/tools/reference/rng.js.map +1 -0
  449. package/dist/tools/reference/scene.d.ts +312 -0
  450. package/dist/tools/reference/scene.js +169 -0
  451. package/dist/tools/reference/scene.js.map +1 -0
  452. package/dist/tools/reference/tables.d.ts +98 -0
  453. package/dist/tools/reference/tables.js +264 -0
  454. package/dist/tools/reference/tables.js.map +1 -0
  455. package/dist/tools/reference/trace.d.ts +160 -0
  456. package/dist/tools/reference/trace.js +497 -0
  457. package/dist/tools/reference/trace.js.map +1 -0
  458. package/dist/tools/vdb/blosc-write.d.ts +43 -0
  459. package/dist/tools/vdb/blosc-write.js +197 -0
  460. package/dist/tools/vdb/blosc-write.js.map +1 -0
  461. package/dist/tools/vdb/blosc.d.ts +35 -5
  462. package/dist/tools/vdb/blosc.js +82 -26
  463. package/dist/tools/vdb/blosc.js.map +1 -1
  464. package/dist/tools/vdb/blosclz.d.ts +33 -0
  465. package/dist/tools/vdb/blosclz.js +112 -0
  466. package/dist/tools/vdb/blosclz.js.map +1 -0
  467. package/dist/tools/vdb/byte-reader.d.ts +13 -3
  468. package/dist/tools/vdb/byte-reader.js +26 -4
  469. package/dist/tools/vdb/byte-reader.js.map +1 -1
  470. package/dist/tools/vdb/compression.d.ts +13 -5
  471. package/dist/tools/vdb/compression.js +13 -2
  472. package/dist/tools/vdb/compression.js.map +1 -1
  473. package/dist/tools/vdb/grid.js +8 -2
  474. package/dist/tools/vdb/grid.js.map +1 -1
  475. package/dist/tools/vdb/index.d.ts +2 -1
  476. package/dist/tools/vdb/index.js.map +1 -1
  477. package/dist/tools/vdb/lz4.d.ts +30 -0
  478. package/dist/tools/vdb/lz4.js +228 -0
  479. package/dist/tools/vdb/lz4.js.map +1 -0
  480. package/dist/tools/vdb/metadata.js +1 -1
  481. package/dist/tools/vdb/metadata.js.map +1 -1
  482. package/dist/tools/vdb/parse.d.ts +24 -2
  483. package/dist/tools/vdb/parse.js +102 -32
  484. package/dist/tools/vdb/parse.js.map +1 -1
  485. package/dist/tools/vdb/point-render-data.d.ts +49 -1
  486. package/dist/tools/vdb/point-render-data.js +91 -11
  487. package/dist/tools/vdb/point-render-data.js.map +1 -1
  488. package/dist/tools/vdb/points.d.ts +26 -0
  489. package/dist/tools/vdb/points.js +46 -5
  490. package/dist/tools/vdb/points.js.map +1 -1
  491. package/dist/tools/vdb/types.d.ts +59 -2
  492. package/dist/tools/vdb/types.js.map +1 -1
  493. package/dist/tools/wvdb/bake.d.ts +38 -9
  494. package/dist/tools/wvdb/bake.js +63 -13
  495. package/dist/tools/wvdb/bake.js.map +1 -1
  496. package/dist/tools/wvdb/dense.d.ts +80 -1
  497. package/dist/tools/wvdb/dense.js +67 -8
  498. package/dist/tools/wvdb/dense.js.map +1 -1
  499. package/dist/tools/wvdb/format.d.ts +59 -0
  500. package/dist/tools/wvdb/format.js +3 -0
  501. package/dist/tools/wvdb/format.js.map +1 -1
  502. package/dist/tools/wvdb/index.d.ts +1 -0
  503. package/dist/tools/wvdb/index.js +1 -0
  504. package/dist/tools/wvdb/index.js.map +1 -1
  505. package/dist/tools/wvdb/level-set.d.ts +10 -2
  506. package/dist/tools/wvdb/level-set.js.map +1 -1
  507. package/dist/tools/wvdb/nanovdb.d.ts +6 -1
  508. package/dist/tools/wvdb/nanovdb.js +5 -1
  509. package/dist/tools/wvdb/nanovdb.js.map +1 -1
  510. package/dist/tools/wvdb/partial.d.ts +74 -0
  511. package/dist/tools/wvdb/partial.js +233 -0
  512. package/dist/tools/wvdb/partial.js.map +1 -0
  513. package/dist/tools/wvdb/read.d.ts +77 -1
  514. package/dist/tools/wvdb/read.js +30 -7
  515. package/dist/tools/wvdb/read.js.map +1 -1
  516. package/dist/tools/wvdb/write.d.ts +23 -1
  517. package/dist/tools/wvdb/write.js +8 -1
  518. package/dist/tools/wvdb/write.js.map +1 -1
  519. package/package.json +2 -1
  520. package/vendor/VENDOR.md +21 -6
  521. package/vendor/pnanovdb.wgsl +52 -14
  522. package/dist/three/frame/blackbody.d.ts +0 -42
  523. package/dist/three/frame/blackbody.js +0 -74
  524. package/dist/three/frame/blackbody.js.map +0 -1
  525. package/dist/three/frame/chunks.d.ts +0 -157
  526. package/dist/three/frame/chunks.js +0 -559
  527. package/dist/three/frame/chunks.js.map +0 -1
  528. package/dist/three/frame/density-material.d.ts +0 -53
  529. package/dist/three/frame/density-material.js +0 -353
  530. package/dist/three/frame/density-material.js.map +0 -1
  531. package/dist/three/frame/environment-grid-material.d.ts +0 -21
  532. package/dist/three/frame/environment-grid-material.js +0 -184
  533. package/dist/three/frame/environment-grid-material.js.map +0 -1
  534. package/dist/three/frame/environment-material.d.ts +0 -22
  535. package/dist/three/frame/environment-material.js +0 -87
  536. package/dist/three/frame/environment-material.js.map +0 -1
  537. package/dist/three/frame/grid-mip-material.d.ts +0 -12
  538. package/dist/three/frame/grid-mip-material.js +0 -61
  539. package/dist/three/frame/grid-mip-material.js.map +0 -1
  540. package/dist/three/frame/inject-material.d.ts +0 -56
  541. package/dist/three/frame/inject-material.js +0 -424
  542. package/dist/three/frame/inject-material.js.map +0 -1
  543. package/dist/three/frame/integrate-material.d.ts +0 -26
  544. package/dist/three/frame/integrate-material.js +0 -198
  545. package/dist/three/frame/integrate-material.js.map +0 -1
  546. package/dist/three/frame/layout.d.ts +0 -34
  547. package/dist/three/frame/layout.js +0 -48
  548. package/dist/three/frame/layout.js.map +0 -1
  549. package/dist/three/frame/lighting-material.d.ts +0 -41
  550. package/dist/three/frame/lighting-material.js +0 -257
  551. package/dist/three/frame/lighting-material.js.map +0 -1
  552. package/dist/three/frame/lights.d.ts +0 -11
  553. package/dist/three/frame/lights.js +0 -16
  554. package/dist/three/frame/lights.js.map +0 -1
  555. package/dist/three/frame/neural.d.ts +0 -14
  556. package/dist/three/frame/neural.js +0 -105
  557. package/dist/three/frame/neural.js.map +0 -1
  558. package/dist/three/frame/phase.d.ts +0 -44
  559. package/dist/three/frame/phase.js +0 -80
  560. package/dist/three/frame/phase.js.map +0 -1
  561. package/dist/three/frame/shadow-density-material.d.ts +0 -30
  562. package/dist/three/frame/shadow-density-material.js +0 -123
  563. package/dist/three/frame/shadow-density-material.js.map +0 -1
  564. package/dist/three/frame/temporal-material.d.ts +0 -29
  565. package/dist/three/frame/temporal-material.js +0 -152
  566. package/dist/three/frame/temporal-material.js.map +0 -1
  567. package/dist/three/frame/transmittance-material.d.ts +0 -31
  568. package/dist/three/frame/transmittance-material.js +0 -315
  569. package/dist/three/frame/transmittance-material.js.map +0 -1
  570. package/dist/three/frame/view.d.ts +0 -103
  571. package/dist/three/frame/view.js +0 -296
  572. package/dist/three/frame/view.js.map +0 -1
  573. package/dist/three/frame/volume-shadow-material.d.ts +0 -36
  574. package/dist/three/frame/volume-shadow-material.js +0 -128
  575. package/dist/three/frame/volume-shadow-material.js.map +0 -1
  576. package/dist/three/sequence.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"level-set.js","sourceRoot":"","sources":["../../../src/tools/wvdb/level-set.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAqB7C,wFAAwF;AACxF,MAAM,cAAc,GAAG,CAAC,CAAC;AAEzB;;;GAGG;AACH,MAAM,UAAU,6BAA6B,CAC3C,MAA0B,EAC1B,IAAoB,EACpB,UAAoB,EACpB,OAAiB,CAAC;IAElB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,GAAG,UAAU,CAAC;IAC1C,MAAM,MAAM,GAAG,IAAI,YAAY,CAAC,KAAK,GAAG,MAAM,GAAG,KAAK,CAAC,CAAC;IACxD,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;IACrC,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,IAAI;QAAE,OAAO,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC1D,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC;IAC5B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,aAAa,CAAC,gBAAgB,EAAE,2CAA2C,MAAM,CAAC,IAAI,yEAAyE,CAAC,CAAC;IAC7K,CAAC;IACD,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,MAAM,IAAI,GAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CA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CAAC,MAAM,CAAC,CAAC,CAAE,EAAE,CAAC,SAAS,CAAC,EAAE,SAAS,CAAC,CAAC;IAC3G,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["/**\n * level-set.ts — mjurczyk's level-set bake sampler (`sampleLevelSet`), an\n * option of the `.wvdb` bake (`levelSetSampler: 'surface-mean'`, K4.13).\n *\n * Portions derived from mjurczyk/openvdb (MIT), commit 75e7345:\n * `src/openvdb/utils/levelSet.js` (`sampleLevelSet`, `getVoxelDistance`,\n * `getTrilinearDistance`) and `src/wvdb/bake.js` (`sampleLevelSetGrid`, the\n * band limit). His arithmetic order is kept so the output is bit-identical.\n *\n * What it does (his notes, restated): a level set's narrow band is often\n * thinner than a texel, so a point sample is only inside or outside and the\n * surface gets steps. When texels are larger than a voxel, a texel whose eight\n * corners do not all have the same sign (it crosses the surface) is the mean\n * of 4x4x4 sub-samples inside it; every other texel is a trilinear sample at\n * its centre (only near the surface; far voxels keep the nearest value). A\n * voxel's distance is its value clamped to `±background` when active, and\n * `±background` by sign when inactive. Finally, values inside the band are\n * clamped one quantization step inside it (`background - 2·background /\n * (2^bits - 1)`) so they never decode as outside.\n *\n * The spec text (§8) instead point-samples and encodes by the source's active\n * state; that stays the default (`levelSetSampler: 'spec'`, DIVERGES V17).\n */\n\nimport { VDBToolsError } from \"../errors.js\";\nimport type { WvdbBits, WvdbBox, WvdbVec3 } from \"./format.js\";\n\n/** Index-space access to a sample source (axis-aligned or affine map). */\nexport interface WvdbIndexAccess {\n /** World position → fractional index coordinate (the grid's inverse map), into `out`. */\n toIndex(world: WvdbVec3, out: WvdbVec3): WvdbVec3;\n /** A world-space vector → index units (the inverse Jacobian), into `out`. */\n toIndexVector(vector: WvdbVec3, out: WvdbVec3): WvdbVec3;\n /** Value and active state of an integer voxel (inactive tile values included). */\n voxel(ijk: [number, number, number]): { value: number; active: boolean };\n}\n\n/** The part of a sample source this sampler reads. */\nexport interface WvdbLevelSetSource {\n name: string;\n background: number;\n bbox: WvdbBox | null;\n index?: WvdbIndexAccess;\n}\n\n/** Sub-samples on each axis for texels that cross the surface (his `filterSamples`). */\nconst FILTER_SAMPLES = 4;\n\n/**\n * His `sampleLevelSetGrid`: samples a level set over `bbox` at `dimensions`\n * (x fastest) and applies the band limit for `bits`.\n */\nexport function sampleWvdbLevelSetSurfaceMean(\n source: WvdbLevelSetSource,\n bbox: WvdbBox | null,\n dimensions: WvdbVec3,\n bits: WvdbBits = 8,\n): Float32Array {\n const [width, height, depth] = dimensions;\n const values = new Float32Array(width * height * depth);\n const background = source.background;\n if (!source.bbox || !bbox) return values.fill(background);\n const access = source.index;\n if (!access) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", `levelSetSampler 'surface-mean': source \"${source.name}\" has no index access (use wvdbSourceFromVdbGrid or wvdbSourceFromNvdb)`);\n }\n const min = bbox[0];\n const size: WvdbVec3 = [bbox[1][0] - min[0], bbox[1][1] - min[1], bbox[1][2] - min[2]];\n\n const world: WvdbVec3 = [0, 0, 0];\n const index: WvdbVec3 = [0, 0, 0];\n const rounded: [number, number, number] = [0, 0, 0];\n const corner: WvdbVec3 = [0, 0, 0];\n\n const toIndex = (x: number, y: number, z: number): WvdbVec3 => {\n world[0] = min[0] + (x / width) * size[0];\n world[1] = min[1] + (y / height) * size[1];\n world[2] = min[2] + (z / depth) * size[2];\n return access.toIndex(world, index);\n };\n\n // His grid.getValue / isActive round the position (Vector3.round: Math.round per axis).\n const lookup = (p: WvdbVec3): { value: number; active: boolean } => {\n rounded[0] = Math.round(p[0]);\n rounded[1] = Math.round(p[1]);\n rounded[2] = Math.round(p[2]);\n return access.voxel(rounded);\n };\n\n // getVoxelDistance: inactive voxels are only outside (+b) or inside (-b); values clamp to the band.\n const voxelDistance = (p: WvdbVec3): number => {\n const { value, active } = lookup(p);\n if (!Number.isFinite(value)) return background;\n if (!active) return value < 0.0 ? -background : background;\n return Math.min(Math.max(value, -background), background);\n };\n\n // getTrilinearDistance: trilinear only near the surface; far voxels keep the nearest value.\n const trilinearDistance = (p: WvdbVec3): number => {\n const nearest = voxelDistance(p);\n if (Math.abs(nearest) >= background) return nearest;\n const x0 = Math.floor(p[0]);\n const y0 = Math.floor(p[1]);\n const z0 = Math.floor(p[2]);\n const wx = p[0] - x0;\n const wy = p[1] - y0;\n const wz = p[2] - z0;\n let value = 0.0;\n for (let i = 0; i < 8; i++) {\n const dx = i & 1;\n const dy = (i >> 1) & 1;\n const dz = (i >> 2) & 1;\n const weight = (dx ? wx : 1.0 - wx) * (dy ? wy : 1.0 - wy) * (dz ? wz : 1.0 - wz);\n if (weight > 0.0) {\n corner[0] = x0 + dx;\n corner[1] = y0 + dy;\n corner[2] = z0 + dz;\n value += weight * voxelDistance(corner);\n }\n }\n return value;\n };\n\n // Texel size in voxels.\n const texel = access.toIndexVector([size[0] / width, size[1] / height, size[2] / depth], [0, 0, 0]);\n const filter = Math.max(Math.abs(texel[0]), Math.abs(texel[1]), Math.abs(texel[2])) > 1.0;\n\n // Signs at texel corners, one corner slice for each side of the texel row.\n const cornersX = width + 1;\n const cornerSlice = cornersX * (height + 1);\n let lowerSigns = new Uint8Array(filter ? cornerSlice : 0);\n let upperSigns = new Uint8Array(filter ? cornerSlice : 0);\n\n const fillSigns = (signs: Uint8Array, z: number): void => {\n for (let y = 0; y <= height; y++) {\n for (let x = 0; x <= width; x++) {\n signs[x + y * cornersX] = lookup(toIndex(x, y, z)).value < 0.0 ? 1 : 0;\n }\n }\n };\n\n const crossesSurface = (x: number, y: number): boolean => {\n const first = lowerSigns[x + y * cornersX];\n for (let i = 1; i < 8; i++) {\n const signs = (i >> 2) & 1 ? upperSigns : lowerSigns;\n if (signs[x + (i & 1) + (y + ((i >> 1) & 1)) * cornersX] !== first) return true;\n }\n return false;\n };\n\n if (filter) fillSigns(lowerSigns, 0);\n const subSamples = FILTER_SAMPLES * FILTER_SAMPLES * FILTER_SAMPLES;\n let offset = 0;\n for (let z = 0; z < depth; z++) {\n if (filter) fillSigns(upperSigns, z + 1);\n for (let y = 0; y < height; y++) {\n for (let x = 0; x < width; x++, offset++) {\n if (filter && crossesSurface(x, y)) {\n let sum = 0.0;\n for (let i = 0; i < subSamples; i++) {\n const sx = (i % FILTER_SAMPLES) + 0.5;\n const sy = (Math.floor(i / FILTER_SAMPLES) % FILTER_SAMPLES) + 0.5;\n const sz = Math.floor(i / (FILTER_SAMPLES * FILTER_SAMPLES)) + 0.5;\n sum += voxelDistance(toIndex(x + sx / FILTER_SAMPLES, y + sy / FILTER_SAMPLES, z + sz / FILTER_SAMPLES));\n }\n values[offset] = sum / subSamples;\n } else {\n values[offset] = trilinearDistance(toIndex(x + 0.5, y + 0.5, z + 0.5));\n }\n }\n }\n [lowerSigns, upperSigns] = [upperSigns, lowerSigns];\n }\n\n // Values in the band stay one quantization step inside it, so they never decode as outside.\n const bandLimit = background - (2.0 * background) / ((1 << bits) - 1);\n for (let i = 0; i < values.length; i++) {\n if (Math.abs(values[i]!) < background) values[i] = Math.min(Math.max(values[i]!, -bandLimit), bandLimit);\n }\n return values;\n}\n"]}
1
+ {"version":3,"file":"level-set.js","sourceRoot":"","sources":["../../../src/tools/wvdb/level-set.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AA6B7C,wFAAwF;AACxF,MAAM,cAAc,GAAG,CAAC,CAAC;AAEzB;;;GAGG;AACH,MAAM,UAAU,6BAA6B,CAC3C,MAA0B,EAC1B,IAAoB,EACpB,UAAoB,EACpB,OAAiB,CAAC;IAElB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,GAAG,UAAU,CAAC;IAC1C,MAAM,MAAM,GAAG,IAAI,YAAY,CAAC,KAAK,GAAG,MAAM,GAAG,KAAK,CAAC,CAAC;IACxD,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;IACrC,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,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AU,EAAE,UAAU,CAAC,GAAG,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IACtD,CAAC;IAED,4FAA4F;IAC5F,MAAM,SAAS,GAAG,UAAU,GAAG,CAAC,GAAG,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IACtE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACvC,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAE,CAAC,GAAG,UAAU;YAAE,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAE,EAAE,CAAC,SAAS,CAAC,EAAE,SAAS,CAAC,CAAC;IAC3G,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["/**\n * level-set.ts — mjurczyk's level-set bake sampler (`sampleLevelSet`), an\n * option of the `.wvdb` bake (`levelSetSampler: 'surface-mean'`, K4.13).\n *\n * Portions derived from mjurczyk/openvdb (MIT), commit 75e7345:\n * `src/openvdb/utils/levelSet.js` (`sampleLevelSet`, `getVoxelDistance`,\n * `getTrilinearDistance`) and `src/wvdb/bake.js` (`sampleLevelSetGrid`, the\n * band limit). His arithmetic order is kept so the output is bit-identical.\n *\n * What it does (his notes, restated): a level set's narrow band is often\n * thinner than a texel, so a point sample is only inside or outside and the\n * surface gets steps. When texels are larger than a voxel, a texel whose eight\n * corners do not all have the same sign (it crosses the surface) is the mean\n * of 4x4x4 sub-samples inside it; every other texel is a trilinear sample at\n * its centre (only near the surface; far voxels keep the nearest value). A\n * voxel's distance is its value clamped to `±background` when active, and\n * `±background` by sign when inactive. Finally, values inside the band are\n * clamped one quantization step inside it (`background - 2·background /\n * (2^bits - 1)`) so they never decode as outside.\n *\n * The spec text (§8) instead point-samples and encodes by the source's active\n * state; that stays the default (`levelSetSampler: 'spec'`, DIVERGES V17).\n */\n\nimport { VDBToolsError } from \"../errors.js\";\nimport type { WvdbBits, WvdbBox, WvdbVec3 } from \"./format.js\";\n\n/** Index-space access to a sample source (axis-aligned or affine map). */\nexport interface WvdbIndexAccess {\n /**\n * World position → fractional index coordinate (the grid's inverse map), into `out`.\n * @param world The world position.\n * @param out Receives the index coordinate (returned).\n */\n toIndex(world: WvdbVec3, out: WvdbVec3): WvdbVec3;\n /**\n * A world-space vector → index units (the inverse Jacobian), into `out`.\n * @param vector The world-space vector.\n * @param out Receives the vector in index units (returned).\n */\n toIndexVector(vector: WvdbVec3, out: WvdbVec3): WvdbVec3;\n /** Value and active state of an integer voxel (inactive tile values included). */\n voxel(ijk: [number, number, number]): { value: number; active: boolean };\n}\n\n/** The part of a sample source this sampler reads. */\nexport interface WvdbLevelSetSource {\n name: string;\n background: number;\n bbox: WvdbBox | null;\n index?: WvdbIndexAccess;\n}\n\n/** Sub-samples on each axis for texels that cross the surface (his `filterSamples`). */\nconst FILTER_SAMPLES = 4;\n\n/**\n * His `sampleLevelSetGrid`: samples a level set over `bbox` at `dimensions`\n * (x fastest) and applies the band limit for `bits`.\n */\nexport function sampleWvdbLevelSetSurfaceMean(\n source: WvdbLevelSetSource,\n bbox: WvdbBox | null,\n dimensions: WvdbVec3,\n bits: WvdbBits = 8,\n): Float32Array {\n const [width, height, depth] = dimensions;\n const values = new Float32Array(width * height * depth);\n const background = source.background;\n if (!source.bbox || !bbox) return values.fill(background);\n const access = source.index;\n if (!access) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", `levelSetSampler 'surface-mean': source \"${source.name}\" has no index access (use wvdbSourceFromVdbGrid or wvdbSourceFromNvdb)`);\n }\n const min = bbox[0];\n const size: WvdbVec3 = [bbox[1][0] - min[0], bbox[1][1] - min[1], bbox[1][2] - min[2]];\n\n const world: WvdbVec3 = [0, 0, 0];\n const index: WvdbVec3 = [0, 0, 0];\n const rounded: [number, number, number] = [0, 0, 0];\n const corner: WvdbVec3 = [0, 0, 0];\n\n const toIndex = (x: number, y: number, z: number): WvdbVec3 => {\n world[0] = min[0] + (x / width) * size[0];\n world[1] = min[1] + (y / height) * size[1];\n world[2] = min[2] + (z / depth) * size[2];\n return access.toIndex(world, index);\n };\n\n // His grid.getValue / isActive round the position (Vector3.round: Math.round per axis).\n const lookup = (p: WvdbVec3): { value: number; active: boolean } => {\n rounded[0] = Math.round(p[0]);\n rounded[1] = Math.round(p[1]);\n rounded[2] = Math.round(p[2]);\n return access.voxel(rounded);\n };\n\n // getVoxelDistance: inactive voxels are only outside (+b) or inside (-b); values clamp to the band.\n const voxelDistance = (p: WvdbVec3): number => {\n const { value, active } = lookup(p);\n if (!Number.isFinite(value)) return background;\n if (!active) return value < 0.0 ? -background : background;\n return Math.min(Math.max(value, -background), background);\n };\n\n // getTrilinearDistance: trilinear only near the surface; far voxels keep the nearest value.\n const trilinearDistance = (p: WvdbVec3): number => {\n const nearest = voxelDistance(p);\n if (Math.abs(nearest) >= background) return nearest;\n const x0 = Math.floor(p[0]);\n const y0 = Math.floor(p[1]);\n const z0 = Math.floor(p[2]);\n const wx = p[0] - x0;\n const wy = p[1] - y0;\n const wz = p[2] - z0;\n let value = 0.0;\n for (let i = 0; i < 8; i++) {\n const dx = i & 1;\n const dy = (i >> 1) & 1;\n const dz = (i >> 2) & 1;\n const weight = (dx ? wx : 1.0 - wx) * (dy ? wy : 1.0 - wy) * (dz ? wz : 1.0 - wz);\n if (weight > 0.0) {\n corner[0] = x0 + dx;\n corner[1] = y0 + dy;\n corner[2] = z0 + dz;\n value += weight * voxelDistance(corner);\n }\n }\n return value;\n };\n\n // Texel size in voxels.\n const texel = access.toIndexVector([size[0] / width, size[1] / height, size[2] / depth], [0, 0, 0]);\n const filter = Math.max(Math.abs(texel[0]), Math.abs(texel[1]), Math.abs(texel[2])) > 1.0;\n\n // Signs at texel corners, one corner slice for each side of the texel row.\n const cornersX = width + 1;\n const cornerSlice = cornersX * (height + 1);\n let lowerSigns = new Uint8Array(filter ? cornerSlice : 0);\n let upperSigns = new Uint8Array(filter ? cornerSlice : 0);\n\n const fillSigns = (signs: Uint8Array, z: number): void => {\n for (let y = 0; y <= height; y++) {\n for (let x = 0; x <= width; x++) {\n signs[x + y * cornersX] = lookup(toIndex(x, y, z)).value < 0.0 ? 1 : 0;\n }\n }\n };\n\n const crossesSurface = (x: number, y: number): boolean => {\n const first = lowerSigns[x + y * cornersX];\n for (let i = 1; i < 8; i++) {\n const signs = (i >> 2) & 1 ? upperSigns : lowerSigns;\n if (signs[x + (i & 1) + (y + ((i >> 1) & 1)) * cornersX] !== first) return true;\n }\n return false;\n };\n\n if (filter) fillSigns(lowerSigns, 0);\n const subSamples = FILTER_SAMPLES * FILTER_SAMPLES * FILTER_SAMPLES;\n let offset = 0;\n for (let z = 0; z < depth; z++) {\n if (filter) fillSigns(upperSigns, z + 1);\n for (let y = 0; y < height; y++) {\n for (let x = 0; x < width; x++, offset++) {\n if (filter && crossesSurface(x, y)) {\n let sum = 0.0;\n for (let i = 0; i < subSamples; i++) {\n const sx = (i % FILTER_SAMPLES) + 0.5;\n const sy = (Math.floor(i / FILTER_SAMPLES) % FILTER_SAMPLES) + 0.5;\n const sz = Math.floor(i / (FILTER_SAMPLES * FILTER_SAMPLES)) + 0.5;\n sum += voxelDistance(toIndex(x + sx / FILTER_SAMPLES, y + sy / FILTER_SAMPLES, z + sz / FILTER_SAMPLES));\n }\n values[offset] = sum / subSamples;\n } else {\n values[offset] = trilinearDistance(toIndex(x + 0.5, y + 0.5, z + 0.5));\n }\n }\n }\n [lowerSigns, upperSigns] = [upperSigns, lowerSigns];\n }\n\n // Values in the band stay one quantization step inside it, so they never decode as outside.\n const bandLimit = background - (2.0 * background) / ((1 << bits) - 1);\n for (let i = 0; i < values.length; i++) {\n if (Math.abs(values[i]!) < background) values[i] = Math.min(Math.max(values[i]!, -bandLimit), bandLimit);\n }\n return values;\n}\n"]}
@@ -18,6 +18,7 @@
18
18
  */
19
19
  import { type VDBBuiltGrid } from "../nanovdb/serialize.js";
20
20
  import type { WvdbDenseVolume } from "./dense.js";
21
+ /** Options of {@link wvdbDenseToNvdb}. */
21
22
  export interface WvdbDenseToNvdbOptions {
22
23
  /** Channel to convert (a scalar one). Default `'density'`. */
23
24
  channel?: "density" | "mask" | "emission";
@@ -50,5 +51,9 @@ export interface WvdbNvdbGrid extends VDBBuiltGrid {
50
51
  readonly bbox?: [[number, number, number], [number, number, number]];
51
52
  };
52
53
  }
53
- /** Converts one scalar channel of a dense `.wvdb` level to a NanoVDB FLOAT grid, voxel for voxel. */
54
+ /**
55
+ * Converts one scalar channel of a dense `.wvdb` level to a NanoVDB FLOAT grid, voxel for voxel.
56
+ * @param volume The dense volume ({@link wvdbDenseVolume}).
57
+ * @param o The channel and the grid name.
58
+ */
54
59
  export declare function wvdbDenseToNvdb(volume: WvdbDenseVolume, o?: WvdbDenseToNvdbOptions): WvdbNvdbGrid;
@@ -18,7 +18,11 @@
18
18
  */
19
19
  import { VDBToolsError } from "../errors.js";
20
20
  import { vdbBuildFromDenseDetailed } from "../nanovdb/serialize.js";
21
- /** Converts one scalar channel of a dense `.wvdb` level to a NanoVDB FLOAT grid, voxel for voxel. */
21
+ /**
22
+ * Converts one scalar channel of a dense `.wvdb` level to a NanoVDB FLOAT grid, voxel for voxel.
23
+ * @param volume The dense volume ({@link wvdbDenseVolume}).
24
+ * @param o The channel and the grid name.
25
+ */
22
26
  export function wvdbDenseToNvdb(volume, o = {}) {
23
27
  const channel = o.channel ?? "density";
24
28
  const tex = volume[channel];
@@ -1 +1 @@
1
- {"version":3,"file":"nanovdb.js","sourceRoot":"","sources":["../../../src/tools/wvdb/nanovdb.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,yBAAyB,EAAqB,MAAM,yBAAyB,CAAC;AA2BvF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1B,QAAQ,EAAE,EAAE,GAAG,EAAE,CAAC,GAAG,eAAe,CAAC,GAAG,CAA6B,EAAE,GAAG,EAAE,CAAC,GAAG,eAAe,CAAC,GAAG,CAA6B,EAAE;QAClI,KAAK,EAAE,EAAE,WAAW,EAAE,MAAM,CAAC,WAAW,EAAE,GAAG,EAAE,MAAM,CAAC,UAAU,EAAE,YAAY,EAAE,MAAM,CAAC,YAAY,EAAE;QACrG,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAyD,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAChH,CAAC;IACF,OAAO,EAAE,GAAG,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAE,CAAC;AAC5D,CAAC","sourcesContent":["/**\n * `.wvdb` dense level → NanoVDB FLOAT grid with identical voxels (K3.2, R1 §6 Step 2 A/B).\n *\n * The sparse-vs-dense A/B renders the same voxels through both samplers, so the only difference\n * is the sampler (hardware trilinear on `r8unorm` vs the sparse 8-tap trilinear). This takes the\n * exact texels the dense source uploads (`wvdbDenseVolume`, his 8-bit `clamp(v / scale, 0, 1)`) and\n * writes each one as the f32 the GPU decodes from `r8unorm`: `k / 255`. Texel `(x, y, z)` becomes\n * index voxel `(x, y, z)`; non-zero texels are active, zero texels are the 0 background (so the\n * grid's stats are the mean of the non-zero texels, his `getDensityStats` rule up to the f32 sum).\n *\n * The unit box of the volume maps to the index box `[0, dims − 1]` (pass it as the sparse source's\n * `indexBox`: the built grid's own bbox is the active voxels' only). The Map scales each axis by that\n * axis's voxel size in the `.wvdb` box (`(bbox.max − bbox.min) / dims`: a bake rounds each side's\n * texel count on its own, so voxels are generally not cubic) with the first voxel centre at\n * `bbox.min + voxel / 2`, where the dense texture puts it. CPU tools (`vdbResampleError`, a\n * world-space sample through the Map) then compare the grid with its source in world space; the\n * froxel renderer places volumes by their box, not the grid's Map. Without a box the Map is the identity.\n */\n\nimport { VDBToolsError } from \"../errors.js\";\nimport { vdbBuildFromDenseDetailed, type VDBBuiltGrid } from \"../nanovdb/serialize.js\";\nimport type { WvdbDenseVolume } from \"./dense.js\";\n\nexport interface WvdbDenseToNvdbOptions {\n /** Channel to convert (a scalar one). Default `'density'`. */\n channel?: \"density\" | \"mask\" | \"emission\";\n /** Grid name. Default: the channel's grid name in the `.wvdb`. */\n gridName?: string;\n}\n\n/** The converted grid plus the index box the dense texture covered. */\nexport interface WvdbNvdbGrid extends VDBBuiltGrid {\n /** `[0, 0, 0]` to `dims − 1`: the dense texture's voxels (inclusive). */\n readonly textureIndexBox: { min: [number, number, number]; max: [number, number, number] };\n /**\n * K5.9: the `vdbSparseSource` options (`@pmndrs/vdb/three`) that line a sparse copy up with the dense source: the\n * texture's index box, the dense density stats (so `normalizeDensity` divides by the same mean) and the `.wvdb`\n * box (when it has one). Spread them in: `vdbSparseSource(grids, { density: id }, { ...grid.sparseSourceOptions, lod })`.\n * For an aux channel (mask, emission) pass `textureIndexBox` as its `auxIndexBoxes` entry instead.\n */\n readonly sparseSourceOptions: {\n readonly indexBox: { min: [number, number, number]; max: [number, number, number] };\n readonly stats: { meanNonZero: number; max: number; activeVoxels: number };\n readonly bbox?: [[number, number, number], [number, number, number]];\n };\n}\n\n/** Converts one scalar channel of a dense `.wvdb` level to a NanoVDB FLOAT grid, voxel for voxel. */\nexport function wvdbDenseToNvdb(volume: WvdbDenseVolume, o: WvdbDenseToNvdbOptions = {}): WvdbNvdbGrid {\n const channel = o.channel ?? \"density\";\n const tex = volume[channel];\n if (!tex) throw new VDBToolsError(\"VDB_BAD_OPTION\", `wvdbDenseToNvdb: the volume has no ${channel} channel`);\n if (tex.texelBytes !== 1) throw new VDBToolsError(\"VDB_BAD_OPTION\", `wvdbDenseToNvdb: the ${channel} channel is not scalar (r8unorm)`);\n const [w, h, d] = tex.dimensions;\n const values = new Float32Array(w * h * d);\n // Texels are x fastest (x + (y + z·h)·w); vdbBuildFromDense reads x-major ((x·h + y)·d + z).\n for (let z = 0; z < d; z++)\n for (let y = 0; y < h; y++)\n for (let x = 0; x < w; x++) values[(x * h + y) * d + z] = tex.data[x + (y + z * h) * w]! / 255;\n const bbox = volume.bbox;\n // Per axis (G15a): a bake rounds each side's texel count on its own, so the voxels are not cubic.\n const voxelSize = [w, h, d].map((n, a) => {\n const v = bbox ? (bbox[1][a]! - bbox[0][a]!) / n : 1;\n return v > 0 && Number.isFinite(v) ? v : 1;\n }) as [number, number, number];\n const worldOrigin: [number, number, number] = bbox\n ? [bbox[0][0] + voxelSize[0] / 2, bbox[0][1] + voxelSize[1] / 2, bbox[0][2] + voxelSize[2] / 2]\n : [0, 0, 0];\n const built = vdbBuildFromDenseDetailed(values, [w, h, d], {\n voxelSize,\n worldOrigin,\n background: 0,\n gridName: o.gridName ?? volume.gridNames[channel] ?? channel,\n gridClass: \"FogVolume\",\n });\n const textureIndexBox = { min: [0, 0, 0] as [number, number, number], max: [w - 1, h - 1, d - 1] as [number, number, number] };\n const sparseSourceOptions = {\n indexBox: { min: [...textureIndexBox.min] as [number, number, number], max: [...textureIndexBox.max] as [number, number, number] },\n stats: { meanNonZero: volume.meanDensity, max: volume.maxDensity, activeVoxels: volume.activeTexels },\n ...(bbox ? { bbox: [[...bbox[0]], [...bbox[1]]] as [[number, number, number], [number, number, number]] } : {}),\n };\n return { ...built, textureIndexBox, sparseSourceOptions };\n}\n"]}
1
+ {"version":3,"file":"nanovdb.js","sourceRoot":"","sources":["../../../src/tools/wvdb/nanovdb.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,yBAAyB,EAAqB,MAAM,yBAAyB,CAAC;AA4BvF;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,MAAuB,EAAE,IAA4B,EAAE;IACrF,MAAM,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GAAG,EAAE,CAAC,GAAG,eAAe,CAAC,GAAG,CAA6B,EAAE;QAClI,KAAK,EAAE,EAAE,WAAW,EAAE,MAAM,CAAC,WAAW,EAAE,GAAG,EAAE,MAAM,CAAC,UAAU,EAAE,YAAY,EAAE,MAAM,CAAC,YAAY,EAAE;QACrG,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAyD,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAChH,CAAC;IACF,OAAO,EAAE,GAAG,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAE,CAAC;AAC5D,CAAC","sourcesContent":["/**\n * `.wvdb` dense level → NanoVDB FLOAT grid with identical voxels (K3.2, R1 §6 Step 2 A/B).\n *\n * The sparse-vs-dense A/B renders the same voxels through both samplers, so the only difference\n * is the sampler (hardware trilinear on `r8unorm` vs the sparse 8-tap trilinear). This takes the\n * exact texels the dense source uploads (`wvdbDenseVolume`, his 8-bit `clamp(v / scale, 0, 1)`) and\n * writes each one as the f32 the GPU decodes from `r8unorm`: `k / 255`. Texel `(x, y, z)` becomes\n * index voxel `(x, y, z)`; non-zero texels are active, zero texels are the 0 background (so the\n * grid's stats are the mean of the non-zero texels, his `getDensityStats` rule up to the f32 sum).\n *\n * The unit box of the volume maps to the index box `[0, dims − 1]` (pass it as the sparse source's\n * `indexBox`: the built grid's own bbox is the active voxels' only). The Map scales each axis by that\n * axis's voxel size in the `.wvdb` box (`(bbox.max − bbox.min) / dims`: a bake rounds each side's\n * texel count on its own, so voxels are generally not cubic) with the first voxel centre at\n * `bbox.min + voxel / 2`, where the dense texture puts it. CPU tools (`vdbResampleError`, a\n * world-space sample through the Map) then compare the grid with its source in world space; the\n * froxel renderer places volumes by their box, not the grid's Map. Without a box the Map is the identity.\n */\n\nimport { VDBToolsError } from \"../errors.js\";\nimport { vdbBuildFromDenseDetailed, type VDBBuiltGrid } from \"../nanovdb/serialize.js\";\nimport type { WvdbDenseVolume } from \"./dense.js\";\n\n/** Options of {@link wvdbDenseToNvdb}. */\nexport interface WvdbDenseToNvdbOptions {\n /** Channel to convert (a scalar one). Default `'density'`. */\n channel?: \"density\" | \"mask\" | \"emission\";\n /** Grid name. Default: the channel's grid name in the `.wvdb`. */\n gridName?: string;\n}\n\n/** The converted grid plus the index box the dense texture covered. */\nexport interface WvdbNvdbGrid extends VDBBuiltGrid {\n /** `[0, 0, 0]` to `dims − 1`: the dense texture's voxels (inclusive). */\n readonly textureIndexBox: { min: [number, number, number]; max: [number, number, number] };\n /**\n * K5.9: the `vdbSparseSource` options (`@pmndrs/vdb/three`) that line a sparse copy up with the dense source: the\n * texture's index box, the dense density stats (so `normalizeDensity` divides by the same mean) and the `.wvdb`\n * box (when it has one). Spread them in: `vdbSparseSource(grids, { density: id }, { ...grid.sparseSourceOptions, lod })`.\n * For an aux channel (mask, emission) pass `textureIndexBox` as its `auxIndexBoxes` entry instead.\n */\n readonly sparseSourceOptions: {\n readonly indexBox: { min: [number, number, number]; max: [number, number, number] };\n readonly stats: { meanNonZero: number; max: number; activeVoxels: number };\n readonly bbox?: [[number, number, number], [number, number, number]];\n };\n}\n\n/**\n * Converts one scalar channel of a dense `.wvdb` level to a NanoVDB FLOAT grid, voxel for voxel.\n * @param volume The dense volume ({@link wvdbDenseVolume}).\n * @param o The channel and the grid name.\n */\nexport function wvdbDenseToNvdb(volume: WvdbDenseVolume, o: WvdbDenseToNvdbOptions = {}): WvdbNvdbGrid {\n const channel = o.channel ?? \"density\";\n const tex = volume[channel];\n if (!tex) throw new VDBToolsError(\"VDB_BAD_OPTION\", `wvdbDenseToNvdb: the volume has no ${channel} channel`);\n if (tex.texelBytes !== 1) throw new VDBToolsError(\"VDB_BAD_OPTION\", `wvdbDenseToNvdb: the ${channel} channel is not scalar (r8unorm)`);\n const [w, h, d] = tex.dimensions;\n const values = new Float32Array(w * h * d);\n // Texels are x fastest (x + (y + z·h)·w); vdbBuildFromDense reads x-major ((x·h + y)·d + z).\n for (let z = 0; z < d; z++)\n for (let y = 0; y < h; y++)\n for (let x = 0; x < w; x++) values[(x * h + y) * d + z] = tex.data[x + (y + z * h) * w]! / 255;\n const bbox = volume.bbox;\n // Per axis (G15a): a bake rounds each side's texel count on its own, so the voxels are not cubic.\n const voxelSize = [w, h, d].map((n, a) => {\n const v = bbox ? (bbox[1][a]! - bbox[0][a]!) / n : 1;\n return v > 0 && Number.isFinite(v) ? v : 1;\n }) as [number, number, number];\n const worldOrigin: [number, number, number] = bbox\n ? [bbox[0][0] + voxelSize[0] / 2, bbox[0][1] + voxelSize[1] / 2, bbox[0][2] + voxelSize[2] / 2]\n : [0, 0, 0];\n const built = vdbBuildFromDenseDetailed(values, [w, h, d], {\n voxelSize,\n worldOrigin,\n background: 0,\n gridName: o.gridName ?? volume.gridNames[channel] ?? channel,\n gridClass: \"FogVolume\",\n });\n const textureIndexBox = { min: [0, 0, 0] as [number, number, number], max: [w - 1, h - 1, d - 1] as [number, number, number] };\n const sparseSourceOptions = {\n indexBox: { min: [...textureIndexBox.min] as [number, number, number], max: [...textureIndexBox.max] as [number, number, number] },\n stats: { meanNonZero: volume.meanDensity, max: volume.maxDensity, activeVoxels: volume.activeTexels },\n ...(bbox ? { bbox: [[...bbox[0]], [...bbox[1]]] as [[number, number, number], [number, number, number]] } : {}),\n };\n return { ...built, textureIndexBox, sparseSourceOptions };\n}\n"]}
@@ -0,0 +1,74 @@
1
+ import type { WvdbFile, WvdbLodEvent, WvdbVolumeLevel } from "./read.js";
2
+ import { type WvdbDenseOptions, type WvdbDenseTexture, type WvdbDenseVolume } from "./dense.js";
3
+ /** How {@link wvdbDensePartialVolume} shows the bricks of a partial LOD that have not arrived yet. */
4
+ export type WvdbDensePartialFill = "upsample" | "background";
5
+ /** Options of {@link wvdbDensePartialVolume}: those of `wvdbDenseVolume` (but the LOD: the event's) and the fill. */
6
+ export interface WvdbDensePartialOptions extends Omit<WvdbDenseOptions, "lod"> {
7
+ /**
8
+ * Bricks stored but not decoded yet: `'upsample'` (default) fills them from the finest complete coarser LOD
9
+ * (his kernel's trilinear upsample; a `fill` on each texture, done by the core's dense source on the GPU or by
10
+ * {@link wvdbDenseResolve}); `'background'` leaves the background there until their page lands.
11
+ */
12
+ fill?: WvdbDensePartialFill;
13
+ /**
14
+ * The mip atlas of an upsampled partial LOD (`WvdbDenseFill.mips`): `'coarse'` (default) takes level 1 of the
15
+ * pending bricks from the coarser LOD, `'box'` builds it from the upsampled texels as his renderer does.
16
+ */
17
+ fillMips?: "coarse" | "box";
18
+ }
19
+ /** Weights are integers in [0, 256]: 8 fractional bits, as a GPU's trilinear filter. */
20
+ export declare const WVDB_UPSAMPLE_WEIGHT_ONE = 256;
21
+ /**
22
+ * One axis of the upsample from `sourceSize` texels to `size` (his `axis`, wvdbKernel.js L125–135): target texel `i`
23
+ * reads source position `clamp((i + ½)·sourceSize/size − ½, 0, sourceSize − 1)`; `lower`/`upper` are the two taps
24
+ * and `weight` the upper tap's weight in 1/256 (the exact fraction rounded half up), in integers.
25
+ */
26
+ export declare function wvdbUpsampleAxis(size: number, sourceSize: number): {
27
+ lower: Uint32Array;
28
+ upper: Uint32Array;
29
+ weight: Uint32Array;
30
+ };
31
+ /** The bricks of `level` that are stored and not decoded yet (one bit per brick), and their count. */
32
+ export declare function wvdbPendingBricks(level: WvdbVolumeLevel): {
33
+ pending: Uint32Array;
34
+ count: number;
35
+ };
36
+ /**
37
+ * CPU twin of the core's fill kernel (`vdbDenseFillCs`): `tex.data` with every pending brick replaced by the
38
+ * coarser texels upsampled to its size, per component, in integers: `c = Σ v · wx · wy · wz` over the 8 taps
39
+ * (weights in 1/256), then `(c + 2²³) >> 24`. Without a fill, a copy of `tex.data`.
40
+ */
41
+ export declare function wvdbUpsampleTexels(tex: WvdbDenseTexture): Uint8Array<ArrayBuffer>;
42
+ /** True when a fill's mip level 1 comes from its coarser LOD: `mips: 'coarse'` and the coarse size is level 1's. */
43
+ export declare function wvdbFillCoarseMips(tex: WvdbDenseTexture): boolean;
44
+ /**
45
+ * CPU twin of a texture's GPU fill: the filled texels and (with a mip atlas) the atlas built from them, level 1 of
46
+ * the pending bricks from the coarser LOD with `mips: 'coarse'` (`vdbDenseMipCs`); no `fill`.
47
+ */
48
+ export declare function wvdbDenseResolveTexture(tex: WvdbDenseTexture): WvdbDenseTexture;
49
+ /**
50
+ * The CPU twin of the core dense source's fill (K4.22): `volume` with every texture's pending bricks upsampled
51
+ * from its coarser LOD and its mip atlas rebuilt from the result, as plain textures (no `fill`). Byte for byte
52
+ * what `vdbDenseSource` uploads for `volume` on the GPU. A host without the core uploads this instead. The
53
+ * stats are `volume`'s (baked, or from the texels with the pending bricks at background).
54
+ */
55
+ export declare function wvdbDenseResolve(volume: WvdbDenseVolume): WvdbDenseVolume;
56
+ /**
57
+ * The dense volume of a `.wvdb` stream event (`WvdbStreamReader({ partialLods: true })`): for a complete LOD,
58
+ * `wvdbDenseVolume(file, { lod })`; for a partial one, the LOD's levels as decoded so far, with (by default) a
59
+ * `fill` on each texture: its stored, undecoded bricks and the finest complete coarser LOD's texels to upsample
60
+ * there. Pass the result to `vdbDenseSource.replace` / `vdbDenseTextures(…).replace` like any LOD; the core fills
61
+ * on the GPU. The texels are copied now: later pages do not change the returned volume.
62
+ *
63
+ * The density mean is the header's baked one when the file has it (scale 1); else it comes from the decoded
64
+ * texels (pending bricks at background), so `normalizeDensity` may move while a LOD streams in. `maxDensity`
65
+ * also bounds the coarse texels (an upsampled texel never exceeds them).
66
+ *
67
+ * const reader = new WvdbStreamReader({ partialLods: true });
68
+ * for (const e of reader.push(bytes)) source.replace(wvdbDensePartialVolume(reader.file!, e));
69
+ *
70
+ * @param file The reader's file (`reader.file`): its grids hold the complete coarser LODs.
71
+ * @param event A stream event (partial or complete).
72
+ * @param o Grids, scales, mipmaps (as `wvdbDenseVolume`) and the fill.
73
+ */
74
+ export declare function wvdbDensePartialVolume(file: WvdbFile, event: WvdbLodEvent, o?: WvdbDensePartialOptions): WvdbDenseVolume;
@@ -0,0 +1,233 @@
1
+ // Portions derived from mjurczyk/openvdb (MIT), commit 75e7345 (v0.26.0):
2
+ // src/three-openvdb/wvdb/wvdbKernel.js upsample L122–188, clearMissingBricks L193–211, chunk L230–344 (a
3
+ // multi-page LOD starts from the previous LOD upsampled to its size, then each page overwrites its bricks).
4
+ // Copyright (c) mjurczyk/openvdb contributors. Licensed under the MIT License (see THIRD_PARTY_NOTICES.md).
5
+ // Changes: per pending brick instead of the whole level; integer weights (8 fractional bits, round half up once at
6
+ // the end) so the core's GPU kernel and this twin agree byte for byte; recomputed from the event's levels on every
7
+ // page (no state). Divergences: DIVERGES.md (K4.22 row).
8
+ /**
9
+ * K4.22: show a `.wvdb` LOD while its pages stream in (spec §12.2). `WvdbStreamReader({ partialLods: true })` emits
10
+ * the LOD's levels after every page; {@link wvdbDensePartialVolume} turns such an event into the dense volume the
11
+ * frame renderer's dense source uploads. With `fill: 'upsample'` (default) the bricks that are stored but not
12
+ * decoded yet are filled from the coarser LOD, as his worker kernel does, so the picture only gains detail; with
13
+ * `fill: 'background'` they stay empty until their page lands.
14
+ *
15
+ * The fill itself runs on the GPU in the core's dense source (`vdbDenseSource`: a compute kernel fills the pending
16
+ * bricks and rebuilds the mip atlas); {@link wvdbDenseResolve} is its CPU twin, byte for byte, and the fallback for
17
+ * hosts without the core.
18
+ */
19
+ import { VDBToolsError } from "../errors.js";
20
+ import { WVDB_BRICK_DIM, brickCounts, isMaskBitSet } from "./format.js";
21
+ import { wvdbDenseAssemble, wvdbDenseFillTexture, wvdbDenseVolume, wvdbMipAtlas, wvdbTexels, } from "./dense.js";
22
+ /** Weights are integers in [0, 256]: 8 fractional bits, as a GPU's trilinear filter. */
23
+ export const WVDB_UPSAMPLE_WEIGHT_ONE = 256;
24
+ /**
25
+ * One axis of the upsample from `sourceSize` texels to `size` (his `axis`, wvdbKernel.js L125–135): target texel `i`
26
+ * reads source position `clamp((i + ½)·sourceSize/size − ½, 0, sourceSize − 1)`; `lower`/`upper` are the two taps
27
+ * and `weight` the upper tap's weight in 1/256 (the exact fraction rounded half up), in integers.
28
+ */
29
+ export function wvdbUpsampleAxis(size, sourceSize) {
30
+ const lower = new Uint32Array(size);
31
+ const upper = new Uint32Array(size);
32
+ const weight = new Uint32Array(size);
33
+ const den = 2 * size;
34
+ for (let i = 0; i < size; i++) {
35
+ // position · den = (2i + 1)·sourceSize − size, clamped to [0, (sourceSize − 1)·den]
36
+ const num = Math.min(Math.max((2 * i + 1) * sourceSize - size, 0), (sourceSize - 1) * den);
37
+ const lo = Math.floor(num / den);
38
+ const r = num - lo * den;
39
+ lower[i] = lo;
40
+ upper[i] = Math.min(lo + 1, sourceSize - 1);
41
+ weight[i] = Math.floor((r * WVDB_UPSAMPLE_WEIGHT_ONE + size) / den);
42
+ }
43
+ return { lower, upper, weight };
44
+ }
45
+ /** The bricks of `level` that are stored and not decoded yet (one bit per brick), and their count. */
46
+ export function wvdbPendingBricks(level) {
47
+ const words = Math.ceil(level.brickTotal / 32);
48
+ const pending = new Uint32Array(words);
49
+ let count = 0;
50
+ // A sparse LOD whose mask has not arrived: nothing is known to be stored.
51
+ if (level.layout === "sparse" && !level.mask)
52
+ return { pending, count };
53
+ for (let w = 0; w < words; w++) {
54
+ const valid = w === words - 1 && level.brickTotal % 32 !== 0 ? (1 << level.brickTotal % 32) - 1 : 0xffffffff;
55
+ const stored = level.layout === "sparse" ? level.mask[w] : valid;
56
+ const bits = (stored & ~level.decoded[w] & valid) >>> 0;
57
+ pending[w] = bits;
58
+ let b = bits;
59
+ while (b) {
60
+ b &= b - 1;
61
+ count++;
62
+ }
63
+ }
64
+ return { pending, count };
65
+ }
66
+ /**
67
+ * CPU twin of the core's fill kernel (`vdbDenseFillCs`): `tex.data` with every pending brick replaced by the
68
+ * coarser texels upsampled to its size, per component, in integers: `c = Σ v · wx · wy · wz` over the 8 taps
69
+ * (weights in 1/256), then `(c + 2²³) >> 24`. Without a fill, a copy of `tex.data`.
70
+ */
71
+ export function wvdbUpsampleTexels(tex) {
72
+ const out = new Uint8Array(tex.data);
73
+ const fill = tex.fill;
74
+ if (!fill || fill.count === 0)
75
+ return out;
76
+ const [w, h, d] = tex.dimensions;
77
+ const [sw, sh, sd] = fill.from.dimensions;
78
+ const tb = tex.texelBytes;
79
+ const src = fill.from.data;
80
+ if (src.length !== sw * sh * sd * tb)
81
+ throw new VDBToolsError("VDB_BAD_OPTION", `wvdbUpsampleTexels: the coarse texels are ${src.length} bytes, expected ${sw}x${sh}x${sd}x${tb}`);
82
+ const ax = wvdbUpsampleAxis(w, sw);
83
+ const ay = wvdbUpsampleAxis(h, sh);
84
+ const az = wvdbUpsampleAxis(d, sd);
85
+ const [cx, cy, cz] = brickCounts(tex.dimensions);
86
+ const ONE = WVDB_UPSAMPLE_WEIGHT_ONE;
87
+ for (let bz = 0; bz < cz; bz++) {
88
+ for (let by = 0; by < cy; by++) {
89
+ for (let bx = 0; bx < cx; bx++) {
90
+ if (!isMaskBitSet(fill.pending, bx + cx * (by + cy * bz)))
91
+ continue;
92
+ for (let z = bz * WVDB_BRICK_DIM; z < Math.min(d, (bz + 1) * WVDB_BRICK_DIM); z++) {
93
+ const z0 = az.lower[z] * sh;
94
+ const z1 = az.upper[z] * sh;
95
+ const wz = az.weight[z];
96
+ for (let y = by * WVDB_BRICK_DIM; y < Math.min(h, (by + 1) * WVDB_BRICK_DIM); y++) {
97
+ const y0 = (ay.lower[y] + z0) * sw;
98
+ const y1 = (ay.upper[y] + z0) * sw;
99
+ const y2 = (ay.lower[y] + z1) * sw;
100
+ const y3 = (ay.upper[y] + z1) * sw;
101
+ const wy = ay.weight[y];
102
+ for (let x = bx * WVDB_BRICK_DIM; x < Math.min(w, (bx + 1) * WVDB_BRICK_DIM); x++) {
103
+ const x0 = ax.lower[x];
104
+ const x1 = ax.upper[x];
105
+ const wx = ax.weight[x];
106
+ const o = (x + (y + z * h) * w) * tb;
107
+ for (let c = 0; c < tb; c++) {
108
+ const at = (i) => src[i * tb + c];
109
+ const c00 = at(x0 + y0) * (ONE - wx) + at(x1 + y0) * wx;
110
+ const c10 = at(x0 + y1) * (ONE - wx) + at(x1 + y1) * wx;
111
+ const c01 = at(x0 + y2) * (ONE - wx) + at(x1 + y2) * wx;
112
+ const c11 = at(x0 + y3) * (ONE - wx) + at(x1 + y3) * wx;
113
+ const c0 = c00 * (ONE - wy) + c10 * wy;
114
+ const c1 = c01 * (ONE - wy) + c11 * wy;
115
+ out[o + c] = Math.floor((c0 * (ONE - wz) + c1 * wz + 0x800000) / 0x1000000);
116
+ }
117
+ }
118
+ }
119
+ }
120
+ }
121
+ }
122
+ }
123
+ return out;
124
+ }
125
+ /** True when a fill's mip level 1 comes from its coarser LOD: `mips: 'coarse'` and the coarse size is level 1's. */
126
+ export function wvdbFillCoarseMips(tex) {
127
+ const f = tex.fill;
128
+ return !!f && (f.mips ?? "coarse") === "coarse" && f.from.dimensions.every((v, a) => v === Math.max(1, Math.ceil(tex.dimensions[a] / 2)));
129
+ }
130
+ /**
131
+ * CPU twin of a texture's GPU fill: the filled texels and (with a mip atlas) the atlas built from them, level 1 of
132
+ * the pending bricks from the coarser LOD with `mips: 'coarse'` (`vdbDenseMipCs`); no `fill`.
133
+ */
134
+ export function wvdbDenseResolveTexture(tex) {
135
+ const fill = tex.fill;
136
+ if (!fill)
137
+ return tex;
138
+ const data = wvdbUpsampleTexels(tex);
139
+ const tb = tex.texelBytes;
140
+ const [cx, cy] = brickCounts(tex.dimensions);
141
+ // Level-1 texel (x, y, z) box-filters level-0 texels 2x..2x+1 (clamped): one brick holds them all (bricks are 8 wide).
142
+ const coarse = fill.count > 0 && wvdbFillCoarseMips(tex)
143
+ ? (l) => {
144
+ for (let z = 0; z < l.depth; z++)
145
+ for (let y = 0; y < l.height; y++)
146
+ for (let x = 0; x < l.width; x++) {
147
+ const b = ((2 * x) >> 3) + cx * (((2 * y) >> 3) + cy * ((2 * z) >> 3));
148
+ if (!isMaskBitSet(fill.pending, b))
149
+ continue;
150
+ const i = (x + l.width * (y + l.height * z)) * tb;
151
+ for (let c = 0; c < tb; c++)
152
+ l.data[i + c] = fill.from.data[i + c];
153
+ }
154
+ }
155
+ : undefined;
156
+ return { data, dimensions: tex.dimensions, format: tex.format, texelBytes: tb, mip: tex.mip ? wvdbMipAtlas(data, tex.dimensions, tb, coarse) : null };
157
+ }
158
+ /**
159
+ * The CPU twin of the core dense source's fill (K4.22): `volume` with every texture's pending bricks upsampled
160
+ * from its coarser LOD and its mip atlas rebuilt from the result, as plain textures (no `fill`). Byte for byte
161
+ * what `vdbDenseSource` uploads for `volume` on the GPU. A host without the core uploads this instead. The
162
+ * stats are `volume`'s (baked, or from the texels with the pending bricks at background).
163
+ */
164
+ export function wvdbDenseResolve(volume) {
165
+ const r = (t) => (t ? wvdbDenseResolveTexture(t) : null);
166
+ return { ...volume, density: r(volume.density), mask: r(volume.mask), albedo: r(volume.albedo), emission: r(volume.emission) };
167
+ }
168
+ /** Coarse texels per level and scale, so every page of a LOD shares one array (the core uploads it once). */
169
+ const coarseTexels = new WeakMap();
170
+ function coarseOf(grid, level, scale) {
171
+ let byScale = coarseTexels.get(level);
172
+ if (!byScale)
173
+ coarseTexels.set(level, (byScale = new Map()));
174
+ let data = byScale.get(scale);
175
+ if (!data)
176
+ byScale.set(scale, (data = wvdbTexels(grid, level, scale)));
177
+ return data;
178
+ }
179
+ /**
180
+ * The dense volume of a `.wvdb` stream event (`WvdbStreamReader({ partialLods: true })`): for a complete LOD,
181
+ * `wvdbDenseVolume(file, { lod })`; for a partial one, the LOD's levels as decoded so far, with (by default) a
182
+ * `fill` on each texture: its stored, undecoded bricks and the finest complete coarser LOD's texels to upsample
183
+ * there. Pass the result to `vdbDenseSource.replace` / `vdbDenseTextures(…).replace` like any LOD; the core fills
184
+ * on the GPU. The texels are copied now: later pages do not change the returned volume.
185
+ *
186
+ * The density mean is the header's baked one when the file has it (scale 1); else it comes from the decoded
187
+ * texels (pending bricks at background), so `normalizeDensity` may move while a LOD streams in. `maxDensity`
188
+ * also bounds the coarse texels (an upsampled texel never exceeds them).
189
+ *
190
+ * const reader = new WvdbStreamReader({ partialLods: true });
191
+ * for (const e of reader.push(bytes)) source.replace(wvdbDensePartialVolume(reader.file!, e));
192
+ *
193
+ * @param file The reader's file (`reader.file`): its grids hold the complete coarser LODs.
194
+ * @param event A stream event (partial or complete).
195
+ * @param o Grids, scales, mipmaps (as `wvdbDenseVolume`) and the fill.
196
+ */
197
+ export function wvdbDensePartialVolume(file, event, o = {}) {
198
+ if (!file || !Array.isArray(file.grids))
199
+ throw new VDBToolsError("VDB_BAD_OPTION", "wvdbDensePartialVolume: pass the stream reader's file (reader.file)");
200
+ if (!event || !Array.isArray(event.levels))
201
+ throw new VDBToolsError("VDB_BAD_OPTION", "wvdbDensePartialVolume: pass a WvdbStreamReader event");
202
+ const fill = o.fill ?? "upsample";
203
+ if (fill !== "upsample" && fill !== "background")
204
+ throw new VDBToolsError("VDB_BAD_OPTION", `wvdbDensePartialVolume: fill must be 'upsample' or 'background', got ${JSON.stringify(o.fill)}`);
205
+ const fillMips = o.fillMips ?? "coarse";
206
+ if (fillMips !== "coarse" && fillMips !== "box")
207
+ throw new VDBToolsError("VDB_BAD_OPTION", `wvdbDensePartialVolume: fillMips must be 'coarse' or 'box', got ${JSON.stringify(o.fillMips)}`);
208
+ const { fill: _fill, fillMips: _fillMips, ...dense } = o;
209
+ if (event.complete)
210
+ return wvdbDenseVolume(file, { ...dense, lod: event.lod });
211
+ const levelOf = (grid) => {
212
+ const level = event.levels[file.grids.indexOf(grid)];
213
+ if (!level || level.kind !== "volume" || level.lod !== event.lod) {
214
+ throw new VDBToolsError("VDB_BAD_OPTION", `wvdbDensePartialVolume: the event has no LOD ${event.lod} level of "${grid.name}" (is it this file's event?)`);
215
+ }
216
+ return level;
217
+ };
218
+ return wvdbDenseAssemble(file, dense, event.lod, {
219
+ level: levelOf,
220
+ texture(grid, level, data, texelBytes, mipmaps, scale) {
221
+ let f = null;
222
+ // The finest complete LOD below this one (the reader completes LODs coarse first).
223
+ const coarse = fill === "upsample" ? grid.levels[Math.min(event.lod, grid.levels.length) - 1] : undefined;
224
+ if (coarse) {
225
+ const { pending, count } = wvdbPendingBricks(level);
226
+ if (count > 0)
227
+ f = { pending, count, from: { data: coarseOf(grid, coarse, scale), dimensions: [...coarse.dimensions] }, mips: fillMips };
228
+ }
229
+ return wvdbDenseFillTexture(data, [...level.dimensions], texelBytes, mipmaps, f);
230
+ },
231
+ });
232
+ }
233
+ //# sourceMappingURL=partial.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"partial.js","sourceRoot":"","sources":["../../../src/tools/wvdb/partial.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,2GAA2G;AAC3G,8GAA8G;AAC9G,4GAA4G;AAC5G,mHAAmH;AACnH,mHAAmH;AACnH,yDAAyD;AAEzD;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,YAAY,EAAiB,MAAM,aAAa,CAAC;AAEvF,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,eAAe,EACf,YAAY,EACZ,UAAU,GAKX,MAAM,YAAY,CAAC;AAoBpB,wFAAwF;AACxF,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,CAAC;AAE5C;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY,EAAE,UAAkB;IAC/D,MAAM,KAAK,GAAG,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC;IACpC,MAAM,KAAK,GAAG,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC;IACpC,MAAM,MAAM,GAAG,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC;IACrC,MAAM,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC;IACrB,KAAK,IAAI,CAAC,GAAG,CAAC,E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from mjurczyk/openvdb (MIT), commit 75e7345 (v0.26.0):\n// src/three-openvdb/wvdb/wvdbKernel.js upsample L122–188, clearMissingBricks L193–211, chunk L230–344 (a\n// multi-page LOD starts from the previous LOD upsampled to its size, then each page overwrites its bricks).\n// Copyright (c) mjurczyk/openvdb contributors. Licensed under the MIT License (see THIRD_PARTY_NOTICES.md).\n// Changes: per pending brick instead of the whole level; integer weights (8 fractional bits, round half up once at\n// the end) so the core's GPU kernel and this twin agree byte for byte; recomputed from the event's levels on every\n// page (no state). Divergences: DIVERGES.md (K4.22 row).\n\n/**\n * K4.22: show a `.wvdb` LOD while its pages stream in (spec §12.2). `WvdbStreamReader({ partialLods: true })` emits\n * the LOD's levels after every page; {@link wvdbDensePartialVolume} turns such an event into the dense volume the\n * frame renderer's dense source uploads. With `fill: 'upsample'` (default) the bricks that are stored but not\n * decoded yet are filled from the coarser LOD, as his worker kernel does, so the picture only gains detail; with\n * `fill: 'background'` they stay empty until their page lands.\n *\n * The fill itself runs on the GPU in the core's dense source (`vdbDenseSource`: a compute kernel fills the pending\n * bricks and rebuilds the mip atlas); {@link wvdbDenseResolve} is its CPU twin, byte for byte, and the fallback for\n * hosts without the core.\n */\n\nimport { VDBToolsError } from \"../errors.js\";\nimport { WVDB_BRICK_DIM, brickCounts, isMaskBitSet, type WvdbVec3 } from \"./format.js\";\nimport type { WvdbFile, WvdbLodEvent, WvdbVolumeGrid, WvdbVolumeLevel } from \"./read.js\";\nimport {\n wvdbDenseAssemble,\n wvdbDenseFillTexture,\n wvdbDenseVolume,\n wvdbMipAtlas,\n wvdbTexels,\n type WvdbDenseFill,\n type WvdbDenseOptions,\n type WvdbDenseTexture,\n type WvdbDenseVolume,\n} from \"./dense.js\";\n\n/** How {@link wvdbDensePartialVolume} shows the bricks of a partial LOD that have not arrived yet. */\nexport type WvdbDensePartialFill = \"upsample\" | \"background\";\n\n/** Options of {@link wvdbDensePartialVolume}: those of `wvdbDenseVolume` (but the LOD: the event's) and the fill. */\nexport interface WvdbDensePartialOptions extends Omit<WvdbDenseOptions, \"lod\"> {\n /**\n * Bricks stored but not decoded yet: `'upsample'` (default) fills them from the finest complete coarser LOD\n * (his kernel's trilinear upsample; a `fill` on each texture, done by the core's dense source on the GPU or by\n * {@link wvdbDenseResolve}); `'background'` leaves the background there until their page lands.\n */\n fill?: WvdbDensePartialFill;\n /**\n * The mip atlas of an upsampled partial LOD (`WvdbDenseFill.mips`): `'coarse'` (default) takes level 1 of the\n * pending bricks from the coarser LOD, `'box'` builds it from the upsampled texels as his renderer does.\n */\n fillMips?: \"coarse\" | \"box\";\n}\n\n/** Weights are integers in [0, 256]: 8 fractional bits, as a GPU's trilinear filter. */\nexport const WVDB_UPSAMPLE_WEIGHT_ONE = 256;\n\n/**\n * One axis of the upsample from `sourceSize` texels to `size` (his `axis`, wvdbKernel.js L125–135): target texel `i`\n * reads source position `clamp((i + ½)·sourceSize/size − ½, 0, sourceSize − 1)`; `lower`/`upper` are the two taps\n * and `weight` the upper tap's weight in 1/256 (the exact fraction rounded half up), in integers.\n */\nexport function wvdbUpsampleAxis(size: number, sourceSize: number): { lower: Uint32Array; upper: Uint32Array; weight: Uint32Array } {\n const lower = new Uint32Array(size);\n const upper = new Uint32Array(size);\n const weight = new Uint32Array(size);\n const den = 2 * size;\n for (let i = 0; i < size; i++) {\n // position · den = (2i + 1)·sourceSize − size, clamped to [0, (sourceSize − 1)·den]\n const num = Math.min(Math.max((2 * i + 1) * sourceSize - size, 0), (sourceSize - 1) * den);\n const lo = Math.floor(num / den);\n const r = num - lo * den;\n lower[i] = lo;\n upper[i] = Math.min(lo + 1, sourceSize - 1);\n weight[i] = Math.floor((r * WVDB_UPSAMPLE_WEIGHT_ONE + size) / den);\n }\n return { lower, upper, weight };\n}\n\n/** The bricks of `level` that are stored and not decoded yet (one bit per brick), and their count. */\nexport function wvdbPendingBricks(level: WvdbVolumeLevel): { pending: Uint32Array; count: number } {\n const words = Math.ceil(level.brickTotal / 32);\n const pending = new Uint32Array(words);\n let count = 0;\n // A sparse LOD whose mask has not arrived: nothing is known to be stored.\n if (level.layout === \"sparse\" && !level.mask) return { pending, count };\n for (let w = 0; w < words; w++) {\n const valid = w === words - 1 && level.brickTotal % 32 !== 0 ? (1 << level.brickTotal % 32) - 1 : 0xffffffff;\n const stored = level.layout === \"sparse\" ? level.mask![w]! : valid;\n const bits = (stored & ~level.decoded[w]! & valid) >>> 0;\n pending[w] = bits;\n let b = bits;\n while (b) {\n b &= b - 1;\n count++;\n }\n }\n return { pending, count };\n}\n\n/**\n * CPU twin of the core's fill kernel (`vdbDenseFillCs`): `tex.data` with every pending brick replaced by the\n * coarser texels upsampled to its size, per component, in integers: `c = Σ v · wx · wy · wz` over the 8 taps\n * (weights in 1/256), then `(c + 2²³) >> 24`. Without a fill, a copy of `tex.data`.\n */\nexport function wvdbUpsampleTexels(tex: WvdbDenseTexture): Uint8Array<ArrayBuffer> {\n const out = new Uint8Array(tex.data);\n const fill = tex.fill;\n if (!fill || fill.count === 0) return out;\n const [w, h, d] = tex.dimensions;\n const [sw, sh, sd] = fill.from.dimensions;\n const tb = tex.texelBytes;\n const src = fill.from.data;\n if (src.length !== sw * sh * sd * tb) throw new VDBToolsError(\"VDB_BAD_OPTION\", `wvdbUpsampleTexels: the coarse texels are ${src.length} bytes, expected ${sw}x${sh}x${sd}x${tb}`);\n const ax = wvdbUpsampleAxis(w, sw);\n const ay = wvdbUpsampleAxis(h, sh);\n const az = wvdbUpsampleAxis(d, sd);\n const [cx, cy, cz] = brickCounts(tex.dimensions);\n const ONE = WVDB_UPSAMPLE_WEIGHT_ONE;\n for (let bz = 0; bz < cz; bz++) {\n for (let by = 0; by < cy; by++) {\n for (let bx = 0; bx < cx; bx++) {\n if (!isMaskBitSet(fill.pending, bx + cx * (by + cy * bz))) continue;\n for (let z = bz * WVDB_BRICK_DIM; z < Math.min(d, (bz + 1) * WVDB_BRICK_DIM); z++) {\n const z0 = az.lower[z]! * sh;\n const z1 = az.upper[z]! * sh;\n const wz = az.weight[z]!;\n for (let y = by * WVDB_BRICK_DIM; y < Math.min(h, (by + 1) * WVDB_BRICK_DIM); y++) {\n const y0 = (ay.lower[y]! + z0) * sw;\n const y1 = (ay.upper[y]! + z0) * sw;\n const y2 = (ay.lower[y]! + z1) * sw;\n const y3 = (ay.upper[y]! + z1) * sw;\n const wy = ay.weight[y]!;\n for (let x = bx * WVDB_BRICK_DIM; x < Math.min(w, (bx + 1) * WVDB_BRICK_DIM); x++) {\n const x0 = ax.lower[x]!;\n const x1 = ax.upper[x]!;\n const wx = ax.weight[x]!;\n const o = (x + (y + z * h) * w) * tb;\n for (let c = 0; c < tb; c++) {\n const at = (i: number) => src[i * tb + c]!;\n const c00 = at(x0 + y0) * (ONE - wx) + at(x1 + y0) * wx;\n const c10 = at(x0 + y1) * (ONE - wx) + at(x1 + y1) * wx;\n const c01 = at(x0 + y2) * (ONE - wx) + at(x1 + y2) * wx;\n const c11 = at(x0 + y3) * (ONE - wx) + at(x1 + y3) * wx;\n const c0 = c00 * (ONE - wy) + c10 * wy;\n const c1 = c01 * (ONE - wy) + c11 * wy;\n out[o + c] = Math.floor((c0 * (ONE - wz) + c1 * wz + 0x800000) / 0x1000000);\n }\n }\n }\n }\n }\n }\n }\n return out;\n}\n\n/** True when a fill's mip level 1 comes from its coarser LOD: `mips: 'coarse'` and the coarse size is level 1's. */\nexport function wvdbFillCoarseMips(tex: WvdbDenseTexture): boolean {\n const f = tex.fill;\n return !!f && (f.mips ?? \"coarse\") === \"coarse\" && f.from.dimensions.every((v, a) => v === Math.max(1, Math.ceil(tex.dimensions[a]! / 2)));\n}\n\n/**\n * CPU twin of a texture's GPU fill: the filled texels and (with a mip atlas) the atlas built from them, level 1 of\n * the pending bricks from the coarser LOD with `mips: 'coarse'` (`vdbDenseMipCs`); no `fill`.\n */\nexport function wvdbDenseResolveTexture(tex: WvdbDenseTexture): WvdbDenseTexture {\n const fill = tex.fill;\n if (!fill) return tex;\n const data = wvdbUpsampleTexels(tex);\n const tb = tex.texelBytes;\n const [cx, cy] = brickCounts(tex.dimensions);\n // Level-1 texel (x, y, z) box-filters level-0 texels 2x..2x+1 (clamped): one brick holds them all (bricks are 8 wide).\n const coarse = fill.count > 0 && wvdbFillCoarseMips(tex)\n ? (l: { data: Uint8Array; width: number; height: number; depth: number }) => {\n for (let z = 0; z < l.depth; z++)\n for (let y = 0; y < l.height; y++)\n for (let x = 0; x < l.width; x++) {\n const b = ((2 * x) >> 3) + cx * (((2 * y) >> 3) + cy * ((2 * z) >> 3));\n if (!isMaskBitSet(fill.pending, b)) continue;\n const i = (x + l.width * (y + l.height * z)) * tb;\n for (let c = 0; c < tb; c++) l.data[i + c] = fill.from.data[i + c]!;\n }\n }\n : undefined;\n return { data, dimensions: tex.dimensions, format: tex.format, texelBytes: tb, mip: tex.mip ? wvdbMipAtlas(data, tex.dimensions, tb, coarse) : null };\n}\n\n/**\n * The CPU twin of the core dense source's fill (K4.22): `volume` with every texture's pending bricks upsampled\n * from its coarser LOD and its mip atlas rebuilt from the result, as plain textures (no `fill`). Byte for byte\n * what `vdbDenseSource` uploads for `volume` on the GPU. A host without the core uploads this instead. The\n * stats are `volume`'s (baked, or from the texels with the pending bricks at background).\n */\nexport function wvdbDenseResolve(volume: WvdbDenseVolume): WvdbDenseVolume {\n const r = (t: WvdbDenseTexture | null) => (t ? wvdbDenseResolveTexture(t) : null);\n return { ...volume, density: r(volume.density)!, mask: r(volume.mask), albedo: r(volume.albedo), emission: r(volume.emission) };\n}\n\n/** Coarse texels per level and scale, so every page of a LOD shares one array (the core uploads it once). */\nconst coarseTexels = new WeakMap<WvdbVolumeLevel, Map<number, Uint8Array<ArrayBuffer>>>();\n\nfunction coarseOf(grid: WvdbVolumeGrid, level: WvdbVolumeLevel, scale: number): Uint8Array<ArrayBuffer> {\n let byScale = coarseTexels.get(level);\n if (!byScale) coarseTexels.set(level, (byScale = new Map()));\n let data = byScale.get(scale);\n if (!data) byScale.set(scale, (data = wvdbTexels(grid, level, scale)));\n return data;\n}\n\n/**\n * The dense volume of a `.wvdb` stream event (`WvdbStreamReader({ partialLods: true })`): for a complete LOD,\n * `wvdbDenseVolume(file, { lod })`; for a partial one, the LOD's levels as decoded so far, with (by default) a\n * `fill` on each texture: its stored, undecoded bricks and the finest complete coarser LOD's texels to upsample\n * there. Pass the result to `vdbDenseSource.replace` / `vdbDenseTextures(…).replace` like any LOD; the core fills\n * on the GPU. The texels are copied now: later pages do not change the returned volume.\n *\n * The density mean is the header's baked one when the file has it (scale 1); else it comes from the decoded\n * texels (pending bricks at background), so `normalizeDensity` may move while a LOD streams in. `maxDensity`\n * also bounds the coarse texels (an upsampled texel never exceeds them).\n *\n * const reader = new WvdbStreamReader({ partialLods: true });\n * for (const e of reader.push(bytes)) source.replace(wvdbDensePartialVolume(reader.file!, e));\n *\n * @param file The reader's file (`reader.file`): its grids hold the complete coarser LODs.\n * @param event A stream event (partial or complete).\n * @param o Grids, scales, mipmaps (as `wvdbDenseVolume`) and the fill.\n */\nexport function wvdbDensePartialVolume(file: WvdbFile, event: WvdbLodEvent, o: WvdbDensePartialOptions = {}): WvdbDenseVolume {\n if (!file || !Array.isArray(file.grids)) throw new VDBToolsError(\"VDB_BAD_OPTION\", \"wvdbDensePartialVolume: pass the stream reader's file (reader.file)\");\n if (!event || !Array.isArray(event.levels)) throw new VDBToolsError(\"VDB_BAD_OPTION\", \"wvdbDensePartialVolume: pass a WvdbStreamReader event\");\n const fill = o.fill ?? \"upsample\";\n if (fill !== \"upsample\" && fill !== \"background\") throw new VDBToolsError(\"VDB_BAD_OPTION\", `wvdbDensePartialVolume: fill must be 'upsample' or 'background', got ${JSON.stringify(o.fill)}`);\n const fillMips = o.fillMips ?? \"coarse\";\n if (fillMips !== \"coarse\" && fillMips !== \"box\") throw new VDBToolsError(\"VDB_BAD_OPTION\", `wvdbDensePartialVolume: fillMips must be 'coarse' or 'box', got ${JSON.stringify(o.fillMips)}`);\n const { fill: _fill, fillMips: _fillMips, ...dense } = o;\n if (event.complete) return wvdbDenseVolume(file, { ...dense, lod: event.lod });\n const levelOf = (grid: WvdbVolumeGrid): WvdbVolumeLevel => {\n const level = event.levels[file.grids.indexOf(grid)];\n if (!level || level.kind !== \"volume\" || level.lod !== event.lod) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", `wvdbDensePartialVolume: the event has no LOD ${event.lod} level of \"${grid.name}\" (is it this file's event?)`);\n }\n return level;\n };\n return wvdbDenseAssemble(file, dense, event.lod, {\n level: levelOf,\n texture(grid, level, data, texelBytes, mipmaps, scale) {\n let f: WvdbDenseFill | null = null;\n // The finest complete LOD below this one (the reader completes LODs coarse first).\n const coarse = fill === \"upsample\" ? grid.levels[Math.min(event.lod, grid.levels.length) - 1] : undefined;\n if (coarse) {\n const { pending, count } = wvdbPendingBricks(level);\n if (count > 0) f = { pending, count, from: { data: coarseOf(grid, coarse, scale), dimensions: [...coarse.dimensions] as WvdbVec3 }, mips: fillMips };\n }\n return wvdbDenseFillTexture(data, [...level.dimensions] as WvdbVec3, texelBytes, mipmaps, f);\n },\n });\n}\n"]}