@pmndrs/vdb 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (570) hide show
  1. package/CHANGELOG.md +727 -0
  2. package/LICENSE +21 -0
  3. package/README.md +496 -2
  4. package/THIRD_PARTY_NOTICES.md +315 -0
  5. package/dist/core/compute/atlas.d.ts +102 -0
  6. package/dist/core/compute/atlas.js +103 -0
  7. package/dist/core/compute/atlas.js.map +1 -0
  8. package/dist/core/compute/index.d.ts +13 -0
  9. package/dist/core/compute/index.js +9 -0
  10. package/dist/core/compute/index.js.map +1 -0
  11. package/dist/core/compute/majorant-build.d.ts +45 -0
  12. package/dist/core/compute/majorant-build.js +193 -0
  13. package/dist/core/compute/majorant-build.js.map +1 -0
  14. package/dist/core/compute/multi-scale.d.ts +155 -0
  15. package/dist/core/compute/multi-scale.js +684 -0
  16. package/dist/core/compute/multi-scale.js.map +1 -0
  17. package/dist/core/compute/pyramid.d.ts +120 -0
  18. package/dist/core/compute/pyramid.js +468 -0
  19. package/dist/core/compute/pyramid.js.map +1 -0
  20. package/dist/core/compute/shared.d.ts +116 -0
  21. package/dist/core/compute/shared.js +211 -0
  22. package/dist/core/compute/shared.js.map +1 -0
  23. package/dist/core/compute/stats.d.ts +78 -0
  24. package/dist/core/compute/stats.js +193 -0
  25. package/dist/core/compute/stats.js.map +1 -0
  26. package/dist/core/compute/value-transform.d.ts +30 -0
  27. package/dist/core/compute/value-transform.js +64 -0
  28. package/dist/core/compute/value-transform.js.map +1 -0
  29. package/dist/core/errors.d.ts +21 -0
  30. package/dist/core/errors.js +17 -0
  31. package/dist/core/errors.js.map +1 -0
  32. package/dist/core/frame/emission.d.ts +85 -0
  33. package/dist/core/frame/emission.js +422 -0
  34. package/dist/core/frame/emission.js.map +1 -0
  35. package/dist/core/frame/environment.d.ts +47 -0
  36. package/dist/core/frame/environment.js +178 -0
  37. package/dist/core/frame/environment.js.map +1 -0
  38. package/dist/core/frame/index.d.ts +39 -0
  39. package/dist/core/frame/index.js +27 -0
  40. package/dist/core/frame/index.js.map +1 -0
  41. package/dist/core/frame/kernels.d.ts +115 -0
  42. package/dist/core/frame/kernels.js +496 -0
  43. package/dist/core/frame/kernels.js.map +1 -0
  44. package/dist/core/frame/limits.d.ts +67 -0
  45. package/dist/core/frame/limits.js +109 -0
  46. package/dist/core/frame/limits.js.map +1 -0
  47. package/dist/core/frame/phase.d.ts +17 -0
  48. package/dist/core/frame/phase.js +53 -0
  49. package/dist/core/frame/phase.js.map +1 -0
  50. package/dist/core/frame/pipelines.d.ts +49 -0
  51. package/dist/core/frame/pipelines.js +147 -0
  52. package/dist/core/frame/pipelines.js.map +1 -0
  53. package/dist/core/frame/renderer.d.ts +122 -0
  54. package/dist/core/frame/renderer.js +1712 -0
  55. package/dist/core/frame/renderer.js.map +1 -0
  56. package/dist/core/frame/resources.d.ts +71 -0
  57. package/dist/core/frame/resources.js +100 -0
  58. package/dist/core/frame/resources.js.map +1 -0
  59. package/dist/core/frame/scattering.d.ts +97 -0
  60. package/dist/core/frame/scattering.js +332 -0
  61. package/dist/core/frame/scattering.js.map +1 -0
  62. package/dist/core/frame/settings.d.ts +243 -0
  63. package/dist/core/frame/settings.js +67 -0
  64. package/dist/core/frame/settings.js.map +1 -0
  65. package/dist/core/frame/shadows.d.ts +55 -0
  66. package/dist/core/frame/shadows.js +460 -0
  67. package/dist/core/frame/shadows.js.map +1 -0
  68. package/dist/core/frame/types.d.ts +415 -0
  69. package/dist/core/frame/types.js +49 -0
  70. package/dist/core/frame/types.js.map +1 -0
  71. package/dist/core/frame/uniforms.d.ts +105 -0
  72. package/dist/core/frame/uniforms.js +276 -0
  73. package/dist/core/frame/uniforms.js.map +1 -0
  74. package/dist/core/frame/wgsl/chunks.d.ts +4 -0
  75. package/dist/core/frame/wgsl/chunks.js +728 -0
  76. package/dist/core/frame/wgsl/chunks.js.map +1 -0
  77. package/dist/core/frame/wgsl/emission.d.ts +82 -0
  78. package/dist/core/frame/wgsl/emission.js +353 -0
  79. package/dist/core/frame/wgsl/emission.js.map +1 -0
  80. package/dist/core/frame/wgsl/environment.d.ts +42 -0
  81. package/dist/core/frame/wgsl/environment.js +711 -0
  82. package/dist/core/frame/wgsl/environment.js.map +1 -0
  83. package/dist/core/frame/wgsl/gather.d.ts +55 -0
  84. package/dist/core/frame/wgsl/gather.js +850 -0
  85. package/dist/core/frame/wgsl/gather.js.map +1 -0
  86. package/dist/core/frame/wgsl/integrate.d.ts +78 -0
  87. package/dist/core/frame/wgsl/integrate.js +213 -0
  88. package/dist/core/frame/wgsl/integrate.js.map +1 -0
  89. package/dist/core/frame/wgsl/lighting.d.ts +103 -0
  90. package/dist/core/frame/wgsl/lighting.js +1636 -0
  91. package/dist/core/frame/wgsl/lighting.js.map +1 -0
  92. package/dist/core/frame/wgsl/occluders.d.ts +20 -0
  93. package/dist/core/frame/wgsl/occluders.js +95 -0
  94. package/dist/core/frame/wgsl/occluders.js.map +1 -0
  95. package/dist/core/frame/wgsl/resolve.d.ts +19 -0
  96. package/dist/core/frame/wgsl/resolve.js +205 -0
  97. package/dist/core/frame/wgsl/resolve.js.map +1 -0
  98. package/dist/core/frame/wgsl/shadows.d.ts +35 -0
  99. package/dist/core/frame/wgsl/shadows.js +328 -0
  100. package/dist/core/frame/wgsl/shadows.js.map +1 -0
  101. package/dist/core/half.d.ts +11 -0
  102. package/dist/core/half.js +22 -0
  103. package/dist/core/half.js.map +1 -0
  104. package/dist/core/index.d.ts +52 -0
  105. package/dist/core/index.js +46 -0
  106. package/dist/core/index.js.map +1 -0
  107. package/dist/core/internal.d.ts +31 -0
  108. package/dist/core/internal.js +32 -0
  109. package/dist/core/internal.js.map +1 -0
  110. package/dist/core/pool/affine.d.ts +34 -0
  111. package/dist/core/pool/affine.js +100 -0
  112. package/dist/core/pool/affine.js.map +1 -0
  113. package/dist/core/pool/allocator.d.ts +32 -0
  114. package/dist/core/pool/allocator.js +81 -0
  115. package/dist/core/pool/allocator.js.map +1 -0
  116. package/dist/core/pool/image-header.d.ts +93 -0
  117. package/dist/core/pool/image-header.js +194 -0
  118. package/dist/core/pool/image-header.js.map +1 -0
  119. package/dist/core/pool/layout.d.ts +198 -0
  120. package/dist/core/pool/layout.js +316 -0
  121. package/dist/core/pool/layout.js.map +1 -0
  122. package/dist/core/pool/limits.d.ts +41 -0
  123. package/dist/core/pool/limits.js +80 -0
  124. package/dist/core/pool/limits.js.map +1 -0
  125. package/dist/core/pool/pool.d.ts +384 -0
  126. package/dist/core/pool/pool.js +1184 -0
  127. package/dist/core/pool/pool.js.map +1 -0
  128. package/dist/core/reference/index.d.ts +6 -0
  129. package/dist/core/reference/index.js +7 -0
  130. package/dist/core/reference/index.js.map +1 -0
  131. package/dist/core/reference/renderer.d.ts +105 -0
  132. package/dist/core/reference/renderer.js +474 -0
  133. package/dist/core/reference/renderer.js.map +1 -0
  134. package/dist/core/reference/wgsl.d.ts +65 -0
  135. package/dist/core/reference/wgsl.js +803 -0
  136. package/dist/core/reference/wgsl.js.map +1 -0
  137. package/dist/core/sequence.d.ts +347 -0
  138. package/dist/core/sequence.js +548 -0
  139. package/dist/core/sequence.js.map +1 -0
  140. package/dist/core/source/brick-cache.d.ts +165 -0
  141. package/dist/core/source/brick-cache.js +627 -0
  142. package/dist/core/source/brick-cache.js.map +1 -0
  143. package/dist/core/source/dense-fill.d.ts +53 -0
  144. package/dist/core/source/dense-fill.js +377 -0
  145. package/dist/core/source/dense-fill.js.map +1 -0
  146. package/dist/core/source/dense.d.ts +50 -0
  147. package/dist/core/source/dense.js +384 -0
  148. package/dist/core/source/dense.js.map +1 -0
  149. package/dist/core/source/sparse-wgsl.d.ts +92 -0
  150. package/dist/core/source/sparse-wgsl.js +481 -0
  151. package/dist/core/source/sparse-wgsl.js.map +1 -0
  152. package/dist/core/source/sparse.d.ts +192 -0
  153. package/dist/core/source/sparse.js +762 -0
  154. package/dist/core/source/sparse.js.map +1 -0
  155. package/dist/core/source/types.d.ts +120 -0
  156. package/dist/core/source/types.js +9 -0
  157. package/dist/core/source/types.js.map +1 -0
  158. package/dist/core/surface/index.d.ts +10 -0
  159. package/dist/core/surface/index.js +9 -0
  160. package/dist/core/surface/index.js.map +1 -0
  161. package/dist/core/surface/level-set-pass.d.ts +140 -0
  162. package/dist/core/surface/level-set-pass.js +291 -0
  163. package/dist/core/surface/level-set-pass.js.map +1 -0
  164. package/dist/core/surface/level-set-wgsl.d.ts +46 -0
  165. package/dist/core/surface/level-set-wgsl.js +99 -0
  166. package/dist/core/surface/level-set-wgsl.js.map +1 -0
  167. package/dist/core/surface/points.d.ts +109 -0
  168. package/dist/core/surface/points.js +226 -0
  169. package/dist/core/surface/points.js.map +1 -0
  170. package/dist/core/types.d.ts +37 -0
  171. package/dist/core/types.js +32 -0
  172. package/dist/core/types.js.map +1 -0
  173. package/dist/core/wgsl/api.d.ts +65 -0
  174. package/dist/core/wgsl/api.js +546 -0
  175. package/dist/core/wgsl/api.js.map +1 -0
  176. package/dist/core/wgsl/generate.d.ts +90 -0
  177. package/dist/core/wgsl/generate.js +678 -0
  178. package/dist/core/wgsl/generate.js.map +1 -0
  179. package/dist/core/wgsl/lean.d.ts +50 -0
  180. package/dist/core/wgsl/lean.js +327 -0
  181. package/dist/core/wgsl/lean.js.map +1 -0
  182. package/dist/core/wgsl/level-set.d.ts +58 -0
  183. package/dist/core/wgsl/level-set.js +200 -0
  184. package/dist/core/wgsl/level-set.js.map +1 -0
  185. package/dist/core/wgsl/majorant.d.ts +62 -0
  186. package/dist/core/wgsl/majorant.js +381 -0
  187. package/dist/core/wgsl/majorant.js.map +1 -0
  188. package/dist/core/wgsl/pnanovdb.chunks.generated.d.ts +14 -0
  189. package/dist/core/wgsl/pnanovdb.chunks.generated.js +333 -0
  190. package/dist/core/wgsl/pnanovdb.chunks.generated.js.map +1 -0
  191. package/dist/core/wgsl/reserved.d.ts +9 -0
  192. package/dist/core/wgsl/reserved.js +26 -0
  193. package/dist/core/wgsl/reserved.js.map +1 -0
  194. package/dist/core/wgsl/types.d.ts +198 -0
  195. package/dist/core/wgsl/types.js +2 -0
  196. package/dist/core/wgsl/types.js.map +1 -0
  197. package/dist/three/coarse-first.d.ts +207 -0
  198. package/dist/three/coarse-first.js +205 -0
  199. package/dist/three/coarse-first.js.map +1 -0
  200. package/dist/three/compute.d.ts +73 -0
  201. package/dist/three/compute.js +66 -0
  202. package/dist/three/compute.js.map +1 -0
  203. package/dist/three/device.d.ts +66 -0
  204. package/dist/three/device.js +62 -0
  205. package/dist/three/device.js.map +1 -0
  206. package/dist/three/frame/core-environment.d.ts +38 -0
  207. package/dist/three/frame/core-environment.js +154 -0
  208. package/dist/three/frame/core-environment.js.map +1 -0
  209. package/dist/three/frame/core-integrate-material.d.ts +34 -0
  210. package/dist/three/frame/core-integrate-material.js +162 -0
  211. package/dist/three/frame/core-integrate-material.js.map +1 -0
  212. package/dist/three/frame/core-occluders.d.ts +53 -0
  213. package/dist/three/frame/core-occluders.js +193 -0
  214. package/dist/three/frame/core-occluders.js.map +1 -0
  215. package/dist/three/frame/core-structs.d.ts +34 -0
  216. package/dist/three/frame/core-structs.js +61 -0
  217. package/dist/three/frame/core-structs.js.map +1 -0
  218. package/dist/three/frame/core-textures.d.ts +41 -0
  219. package/dist/three/frame/core-textures.js +114 -0
  220. package/dist/three/frame/core-textures.js.map +1 -0
  221. package/dist/three/frame/emission-light.d.ts +117 -0
  222. package/dist/three/frame/emission-light.js +276 -0
  223. package/dist/three/frame/emission-light.js.map +1 -0
  224. package/dist/three/frame/index.d.ts +19 -0
  225. package/dist/three/frame/index.js +15 -0
  226. package/dist/three/frame/index.js.map +1 -0
  227. package/dist/three/frame/medium.d.ts +33 -0
  228. package/dist/three/frame/medium.js +29 -0
  229. package/dist/three/frame/medium.js.map +1 -0
  230. package/dist/three/frame/renderer.d.ts +97 -0
  231. package/dist/three/frame/renderer.js +480 -0
  232. package/dist/three/frame/renderer.js.map +1 -0
  233. package/dist/three/frame/spectrum.d.ts +4 -0
  234. package/dist/three/frame/spectrum.js +15 -0
  235. package/dist/three/frame/spectrum.js.map +1 -0
  236. package/dist/three/frame/three-internals.d.ts +60 -0
  237. package/dist/three/frame/three-internals.js +152 -0
  238. package/dist/three/frame/three-internals.js.map +1 -0
  239. package/dist/three/frame/volume-shadows.d.ts +139 -0
  240. package/dist/three/frame/volume-shadows.js +403 -0
  241. package/dist/three/frame/volume-shadows.js.map +1 -0
  242. package/dist/three/frame/volume.d.ts +230 -0
  243. package/dist/three/frame/volume.js +268 -0
  244. package/dist/three/frame/volume.js.map +1 -0
  245. package/dist/three/grid-node.d.ts +229 -0
  246. package/dist/three/grid-node.js +545 -0
  247. package/dist/three/grid-node.js.map +1 -0
  248. package/dist/three/index.d.ts +52 -0
  249. package/dist/three/index.js +58 -0
  250. package/dist/three/index.js.map +1 -0
  251. package/dist/three/internal.d.ts +20 -0
  252. package/dist/three/internal.js +18 -0
  253. package/dist/three/internal.js.map +1 -0
  254. package/dist/three/level-set-material.d.ts +185 -0
  255. package/dist/three/level-set-material.js +241 -0
  256. package/dist/three/level-set-material.js.map +1 -0
  257. package/dist/three/level-set-physical-material.d.ts +154 -0
  258. package/dist/three/level-set-physical-material.js +253 -0
  259. package/dist/three/level-set-physical-material.js.map +1 -0
  260. package/dist/three/level-set-velocity.d.ts +94 -0
  261. package/dist/three/level-set-velocity.js +208 -0
  262. package/dist/three/level-set-velocity.js.map +1 -0
  263. package/dist/three/material.d.ts +324 -0
  264. package/dist/three/material.js +502 -0
  265. package/dist/three/material.js.map +1 -0
  266. package/dist/three/points.d.ts +140 -0
  267. package/dist/three/points.js +261 -0
  268. package/dist/three/points.js.map +1 -0
  269. package/dist/three/sparse-source.d.ts +165 -0
  270. package/dist/three/sparse-source.js +405 -0
  271. package/dist/three/sparse-source.js.map +1 -0
  272. package/dist/three/volume-source.d.ts +22 -0
  273. package/dist/three/volume-source.js +110 -0
  274. package/dist/three/volume-source.js.map +1 -0
  275. package/dist/tools/cpu/brick-atlas.d.ts +36 -0
  276. package/dist/tools/cpu/brick-atlas.js +129 -0
  277. package/dist/tools/cpu/brick-atlas.js.map +1 -0
  278. package/dist/tools/cpu/compute.d.ts +116 -0
  279. package/dist/tools/cpu/compute.js +239 -0
  280. package/dist/tools/cpu/compute.js.map +1 -0
  281. package/dist/tools/cpu/lean-reads.d.ts +81 -0
  282. package/dist/tools/cpu/lean-reads.js +262 -0
  283. package/dist/tools/cpu/lean-reads.js.map +1 -0
  284. package/dist/tools/cpu/level-set.d.ts +111 -0
  285. package/dist/tools/cpu/level-set.js +313 -0
  286. package/dist/tools/cpu/level-set.js.map +1 -0
  287. package/dist/tools/cpu/majorant.d.ts +265 -0
  288. package/dist/tools/cpu/majorant.js +541 -0
  289. package/dist/tools/cpu/majorant.js.map +1 -0
  290. package/dist/tools/cpu/march.d.ts +297 -0
  291. package/dist/tools/cpu/march.js +726 -0
  292. package/dist/tools/cpu/march.js.map +1 -0
  293. package/dist/tools/cpu/mesh-decimate.d.ts +124 -0
  294. package/dist/tools/cpu/mesh-decimate.js +1225 -0
  295. package/dist/tools/cpu/mesh-decimate.js.map +1 -0
  296. package/dist/tools/cpu/points.d.ts +29 -0
  297. package/dist/tools/cpu/points.js +38 -0
  298. package/dist/tools/cpu/points.js.map +1 -0
  299. package/dist/tools/cpu/probe-coords.d.ts +70 -0
  300. package/dist/tools/cpu/probe-coords.js +116 -0
  301. package/dist/tools/cpu/probe-coords.js.map +1 -0
  302. package/dist/tools/cpu/read-value.d.ts +44 -0
  303. package/dist/tools/cpu/read-value.js +351 -0
  304. package/dist/tools/cpu/read-value.js.map +1 -0
  305. package/dist/tools/cpu/sample-trilinear.d.ts +43 -0
  306. package/dist/tools/cpu/sample-trilinear.js +168 -0
  307. package/dist/tools/cpu/sample-trilinear.js.map +1 -0
  308. package/dist/tools/cpu/stride-tables.d.ts +56 -0
  309. package/dist/tools/cpu/stride-tables.generated.d.ts +1059 -0
  310. package/dist/tools/cpu/stride-tables.generated.js +1267 -0
  311. package/dist/tools/cpu/stride-tables.generated.js.map +1 -0
  312. package/dist/tools/cpu/stride-tables.js +78 -0
  313. package/dist/tools/cpu/stride-tables.js.map +1 -0
  314. package/dist/tools/cpu/surface-nets.d.ts +90 -0
  315. package/dist/tools/cpu/surface-nets.js +597 -0
  316. package/dist/tools/cpu/surface-nets.js.map +1 -0
  317. package/dist/tools/errors.d.ts +66 -0
  318. package/dist/tools/errors.js +67 -0
  319. package/dist/tools/errors.js.map +1 -0
  320. package/dist/tools/frame/ambient.d.ts +98 -0
  321. package/dist/tools/frame/ambient.js +274 -0
  322. package/dist/tools/frame/ambient.js.map +1 -0
  323. package/dist/tools/frame/blackbody.d.ts +57 -0
  324. package/dist/tools/frame/blackbody.js +151 -0
  325. package/dist/tools/frame/blackbody.js.map +1 -0
  326. package/dist/tools/frame/brick-cache.d.ts +165 -0
  327. package/dist/tools/frame/brick-cache.js +326 -0
  328. package/dist/tools/frame/brick-cache.js.map +1 -0
  329. package/dist/tools/frame/emission.d.ts +137 -0
  330. package/dist/tools/frame/emission.js +290 -0
  331. package/dist/tools/frame/emission.js.map +1 -0
  332. package/dist/tools/frame/environment-gpu.d.ts +111 -0
  333. package/dist/tools/frame/environment-gpu.js +280 -0
  334. package/dist/tools/frame/environment-gpu.js.map +1 -0
  335. package/dist/tools/frame/environment.d.ts +106 -0
  336. package/dist/tools/frame/environment.js +272 -0
  337. package/dist/tools/frame/environment.js.map +1 -0
  338. package/dist/tools/frame/froxel.d.ts +58 -0
  339. package/dist/tools/frame/froxel.js +115 -0
  340. package/dist/tools/frame/froxel.js.map +1 -0
  341. package/dist/tools/frame/grid.d.ts +392 -0
  342. package/dist/tools/frame/grid.js +802 -0
  343. package/dist/tools/frame/grid.js.map +1 -0
  344. package/dist/tools/frame/index.d.ts +150 -0
  345. package/dist/tools/frame/index.js +389 -0
  346. package/dist/tools/frame/index.js.map +1 -0
  347. package/dist/tools/frame/medium.d.ts +77 -0
  348. package/dist/tools/frame/medium.js +101 -0
  349. package/dist/tools/frame/medium.js.map +1 -0
  350. package/dist/tools/frame/mie-table.d.ts +6 -0
  351. package/dist/tools/frame/mie-table.js +16 -0
  352. package/dist/tools/frame/mie-table.js.map +1 -0
  353. package/dist/tools/frame/mie.d.ts +63 -0
  354. package/dist/tools/frame/mie.js +194 -0
  355. package/dist/tools/frame/mie.js.map +1 -0
  356. package/dist/tools/frame/mlp-nn.d.ts +36 -0
  357. package/dist/tools/frame/mlp-nn.js +159 -0
  358. package/dist/tools/frame/mlp-nn.js.map +1 -0
  359. package/dist/tools/frame/mlp-tza.d.ts +29 -0
  360. package/dist/tools/frame/mlp-tza.js +186 -0
  361. package/dist/tools/frame/mlp-tza.js.map +1 -0
  362. package/dist/tools/frame/mlp.d.ts +183 -0
  363. package/dist/tools/frame/mlp.js +434 -0
  364. package/dist/tools/frame/mlp.js.map +1 -0
  365. package/dist/tools/frame/ms-exit.d.ts +42 -0
  366. package/dist/tools/frame/ms-exit.js +90 -0
  367. package/dist/tools/frame/ms-exit.js.map +1 -0
  368. package/dist/tools/frame/multi-scale.d.ts +152 -0
  369. package/dist/tools/frame/multi-scale.js +302 -0
  370. package/dist/tools/frame/multi-scale.js.map +1 -0
  371. package/dist/tools/frame/neural-weights.d.ts +10 -0
  372. package/dist/tools/frame/neural-weights.js +244 -0
  373. package/dist/tools/frame/neural-weights.js.map +1 -0
  374. package/dist/tools/frame/neural.d.ts +80 -0
  375. package/dist/tools/frame/neural.js +150 -0
  376. package/dist/tools/frame/neural.js.map +1 -0
  377. package/dist/tools/frame/occluders.d.ts +51 -0
  378. package/dist/tools/frame/occluders.js +72 -0
  379. package/dist/tools/frame/occluders.js.map +1 -0
  380. package/dist/tools/frame/pyramid-layout.d.ts +55 -0
  381. package/dist/tools/frame/pyramid-layout.js +100 -0
  382. package/dist/tools/frame/pyramid-layout.js.map +1 -0
  383. package/dist/tools/frame/shadows.d.ts +190 -0
  384. package/dist/tools/frame/shadows.js +468 -0
  385. package/dist/tools/frame/shadows.js.map +1 -0
  386. package/dist/tools/frame/sparse.d.ts +147 -0
  387. package/dist/tools/frame/sparse.js +432 -0
  388. package/dist/tools/frame/sparse.js.map +1 -0
  389. package/dist/tools/frame/spectral-stack.d.ts +159 -0
  390. package/dist/tools/frame/spectral-stack.js +391 -0
  391. package/dist/tools/frame/spectral-stack.js.map +1 -0
  392. package/dist/tools/frame/spectral.d.ts +222 -0
  393. package/dist/tools/frame/spectral.js +572 -0
  394. package/dist/tools/frame/spectral.js.map +1 -0
  395. package/dist/tools/frame/stack.d.ts +115 -0
  396. package/dist/tools/frame/stack.js +290 -0
  397. package/dist/tools/frame/stack.js.map +1 -0
  398. package/dist/tools/frame/view.d.ts +131 -0
  399. package/dist/tools/frame/view.js +337 -0
  400. package/dist/tools/frame/view.js.map +1 -0
  401. package/dist/tools/index.d.ts +157 -0
  402. package/dist/tools/index.js +132 -0
  403. package/dist/tools/index.js.map +1 -0
  404. package/dist/tools/internal.d.ts +87 -0
  405. package/dist/tools/internal.js +85 -0
  406. package/dist/tools/internal.js.map +1 -0
  407. package/dist/tools/nanovdb/build-from-vdb.d.ts +59 -0
  408. package/dist/tools/nanovdb/build-from-vdb.js +100 -0
  409. package/dist/tools/nanovdb/build-from-vdb.js.map +1 -0
  410. package/dist/tools/nanovdb/bytes.d.ts +233 -0
  411. package/dist/tools/nanovdb/bytes.js +388 -0
  412. package/dist/tools/nanovdb/bytes.js.map +1 -0
  413. package/dist/tools/nanovdb/coarse-first.d.ts +78 -0
  414. package/dist/tools/nanovdb/coarse-first.js +92 -0
  415. package/dist/tools/nanovdb/coarse-first.js.map +1 -0
  416. package/dist/tools/nanovdb/half.d.ts +22 -0
  417. package/dist/tools/nanovdb/half.js +73 -0
  418. package/dist/tools/nanovdb/half.js.map +1 -0
  419. package/dist/tools/nanovdb/index.d.ts +34 -0
  420. package/dist/tools/nanovdb/index.js +25 -0
  421. package/dist/tools/nanovdb/index.js.map +1 -0
  422. package/dist/tools/nanovdb/inspect.d.ts +33 -0
  423. package/dist/tools/nanovdb/inspect.js +70 -0
  424. package/dist/tools/nanovdb/inspect.js.map +1 -0
  425. package/dist/tools/nanovdb/leaf-codec.d.ts +119 -0
  426. package/dist/tools/nanovdb/leaf-codec.js +356 -0
  427. package/dist/tools/nanovdb/leaf-codec.js.map +1 -0
  428. package/dist/tools/nanovdb/quantize.d.ts +72 -0
  429. package/dist/tools/nanovdb/quantize.js +329 -0
  430. package/dist/tools/nanovdb/quantize.js.map +1 -0
  431. package/dist/tools/nanovdb/resample.d.ts +177 -0
  432. package/dist/tools/nanovdb/resample.js +692 -0
  433. package/dist/tools/nanovdb/resample.js.map +1 -0
  434. package/dist/tools/nanovdb/serialize.d.ts +176 -0
  435. package/dist/tools/nanovdb/serialize.js +439 -0
  436. package/dist/tools/nanovdb/serialize.js.map +1 -0
  437. package/dist/tools/nanovdb/stats.d.ts +87 -0
  438. package/dist/tools/nanovdb/stats.js +225 -0
  439. package/dist/tools/nanovdb/stats.js.map +1 -0
  440. package/dist/tools/nanovdb/transform.d.ts +30 -0
  441. package/dist/tools/nanovdb/transform.js +94 -0
  442. package/dist/tools/nanovdb/transform.js.map +1 -0
  443. package/dist/tools/nanovdb/tree.d.ts +186 -0
  444. package/dist/tools/nanovdb/tree.js +530 -0
  445. package/dist/tools/nanovdb/tree.js.map +1 -0
  446. package/dist/tools/nanovdb/write-nvdb.d.ts +74 -0
  447. package/dist/tools/nanovdb/write-nvdb.js +290 -0
  448. package/dist/tools/nanovdb/write-nvdb.js.map +1 -0
  449. package/dist/tools/nvdb-file.d.ts +265 -0
  450. package/dist/tools/nvdb-file.js +763 -0
  451. package/dist/tools/nvdb-file.js.map +1 -0
  452. package/dist/tools/nvdb-stream.d.ts +154 -0
  453. package/dist/tools/nvdb-stream.js +409 -0
  454. package/dist/tools/nvdb-stream.js.map +1 -0
  455. package/dist/tools/reference/analytic.d.ts +41 -0
  456. package/dist/tools/reference/analytic.js +95 -0
  457. package/dist/tools/reference/analytic.js.map +1 -0
  458. package/dist/tools/reference/environment.d.ts +62 -0
  459. package/dist/tools/reference/environment.js +154 -0
  460. package/dist/tools/reference/environment.js.map +1 -0
  461. package/dist/tools/reference/index.d.ts +12 -0
  462. package/dist/tools/reference/index.js +13 -0
  463. package/dist/tools/reference/index.js.map +1 -0
  464. package/dist/tools/reference/media.d.ts +14 -0
  465. package/dist/tools/reference/media.js +30 -0
  466. package/dist/tools/reference/media.js.map +1 -0
  467. package/dist/tools/reference/rng.d.ts +20 -0
  468. package/dist/tools/reference/rng.js +30 -0
  469. package/dist/tools/reference/rng.js.map +1 -0
  470. package/dist/tools/reference/scene.d.ts +312 -0
  471. package/dist/tools/reference/scene.js +169 -0
  472. package/dist/tools/reference/scene.js.map +1 -0
  473. package/dist/tools/reference/tables.d.ts +98 -0
  474. package/dist/tools/reference/tables.js +264 -0
  475. package/dist/tools/reference/tables.js.map +1 -0
  476. package/dist/tools/reference/trace.d.ts +160 -0
  477. package/dist/tools/reference/trace.js +497 -0
  478. package/dist/tools/reference/trace.js.map +1 -0
  479. package/dist/tools/vdb/bit-utils.d.ts +20 -0
  480. package/dist/tools/vdb/bit-utils.js +42 -0
  481. package/dist/tools/vdb/bit-utils.js.map +1 -0
  482. package/dist/tools/vdb/blosc-write.d.ts +43 -0
  483. package/dist/tools/vdb/blosc-write.js +197 -0
  484. package/dist/tools/vdb/blosc-write.js.map +1 -0
  485. package/dist/tools/vdb/blosc.d.ts +86 -0
  486. package/dist/tools/vdb/blosc.js +287 -0
  487. package/dist/tools/vdb/blosc.js.map +1 -0
  488. package/dist/tools/vdb/blosclz.d.ts +33 -0
  489. package/dist/tools/vdb/blosclz.js +112 -0
  490. package/dist/tools/vdb/blosclz.js.map +1 -0
  491. package/dist/tools/vdb/byte-reader.d.ts +50 -0
  492. package/dist/tools/vdb/byte-reader.js +161 -0
  493. package/dist/tools/vdb/byte-reader.js.map +1 -0
  494. package/dist/tools/vdb/compression.d.ts +81 -0
  495. package/dist/tools/vdb/compression.js +260 -0
  496. package/dist/tools/vdb/compression.js.map +1 -0
  497. package/dist/tools/vdb/errors.d.ts +10 -0
  498. package/dist/tools/vdb/errors.js +11 -0
  499. package/dist/tools/vdb/errors.js.map +1 -0
  500. package/dist/tools/vdb/grid.d.ts +37 -0
  501. package/dist/tools/vdb/grid.js +153 -0
  502. package/dist/tools/vdb/grid.js.map +1 -0
  503. package/dist/tools/vdb/half-float.d.ts +9 -0
  504. package/dist/tools/vdb/half-float.js +24 -0
  505. package/dist/tools/vdb/half-float.js.map +1 -0
  506. package/dist/tools/vdb/index.d.ts +4 -0
  507. package/dist/tools/vdb/index.js +3 -0
  508. package/dist/tools/vdb/index.js.map +1 -0
  509. package/dist/tools/vdb/inflate.d.ts +24 -0
  510. package/dist/tools/vdb/inflate.js +334 -0
  511. package/dist/tools/vdb/inflate.js.map +1 -0
  512. package/dist/tools/vdb/lz4.d.ts +30 -0
  513. package/dist/tools/vdb/lz4.js +228 -0
  514. package/dist/tools/vdb/lz4.js.map +1 -0
  515. package/dist/tools/vdb/metadata.d.ts +17 -0
  516. package/dist/tools/vdb/metadata.js +72 -0
  517. package/dist/tools/vdb/metadata.js.map +1 -0
  518. package/dist/tools/vdb/parse.d.ts +47 -0
  519. package/dist/tools/vdb/parse.js +241 -0
  520. package/dist/tools/vdb/parse.js.map +1 -0
  521. package/dist/tools/vdb/point-render-data.d.ts +79 -0
  522. package/dist/tools/vdb/point-render-data.js +137 -0
  523. package/dist/tools/vdb/point-render-data.js.map +1 -0
  524. package/dist/tools/vdb/points.d.ts +186 -0
  525. package/dist/tools/vdb/points.js +835 -0
  526. package/dist/tools/vdb/points.js.map +1 -0
  527. package/dist/tools/vdb/transform.d.ts +23 -0
  528. package/dist/tools/vdb/transform.js +54 -0
  529. package/dist/tools/vdb/transform.js.map +1 -0
  530. package/dist/tools/vdb/tree.d.ts +111 -0
  531. package/dist/tools/vdb/tree.js +228 -0
  532. package/dist/tools/vdb/tree.js.map +1 -0
  533. package/dist/tools/vdb/types.d.ts +195 -0
  534. package/dist/tools/vdb/types.js +3 -0
  535. package/dist/tools/vdb/types.js.map +1 -0
  536. package/dist/tools/wvdb/bake.d.ts +145 -0
  537. package/dist/tools/wvdb/bake.js +361 -0
  538. package/dist/tools/wvdb/bake.js.map +1 -0
  539. package/dist/tools/wvdb/dense.d.ts +191 -0
  540. package/dist/tools/wvdb/dense.js +368 -0
  541. package/dist/tools/wvdb/dense.js.map +1 -0
  542. package/dist/tools/wvdb/format.d.ts +220 -0
  543. package/dist/tools/wvdb/format.js +306 -0
  544. package/dist/tools/wvdb/format.js.map +1 -0
  545. package/dist/tools/wvdb/index.d.ts +14 -0
  546. package/dist/tools/wvdb/index.js +15 -0
  547. package/dist/tools/wvdb/index.js.map +1 -0
  548. package/dist/tools/wvdb/level-set.d.ts +56 -0
  549. package/dist/tools/wvdb/level-set.js +153 -0
  550. package/dist/tools/wvdb/level-set.js.map +1 -0
  551. package/dist/tools/wvdb/nanovdb.d.ts +59 -0
  552. package/dist/tools/wvdb/nanovdb.js +64 -0
  553. package/dist/tools/wvdb/nanovdb.js.map +1 -0
  554. package/dist/tools/wvdb/partial.d.ts +74 -0
  555. package/dist/tools/wvdb/partial.js +233 -0
  556. package/dist/tools/wvdb/partial.js.map +1 -0
  557. package/dist/tools/wvdb/read.d.ts +336 -0
  558. package/dist/tools/wvdb/read.js +766 -0
  559. package/dist/tools/wvdb/read.js.map +1 -0
  560. package/dist/tools/wvdb/sha256.d.ts +7 -0
  561. package/dist/tools/wvdb/sha256.js +76 -0
  562. package/dist/tools/wvdb/sha256.js.map +1 -0
  563. package/dist/tools/wvdb/write.d.ts +149 -0
  564. package/dist/tools/wvdb/write.js +403 -0
  565. package/dist/tools/wvdb/write.js.map +1 -0
  566. package/package.json +83 -4
  567. package/vendor/LICENSE +201 -0
  568. package/vendor/NOTICE +19 -0
  569. package/vendor/VENDOR.md +100 -0
  570. package/vendor/pnanovdb.wgsl +1577 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mie.js","sourceRoot":"","sources":["../../../src/t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,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC1F,CAAC","sourcesContent":["// Portions derived from mjurczyk/openvdb (MIT), commit 75e7345 (v0.26.0):\n// scripts/mie-phase-table.mjs L12–147 (the BHMIE droplet sum, the Deirmendjian C1 radius integral,\n// the sphere normalization and the asymmetry; the generator of his frameMieTable.js /\n// frameMieRgbTable.js), src/three-openvdb/frame/core/framePhase.js L61–76 (getFrameMieTexels),\n// src/three-openvdb/frame/webgpu/frameShaderChunks.js L250–271 (frameMieTexel, the 'lorenz-mie' and\n// 'lorenz-mie-rgb' table reads).\n// Copyright (c) mjurczyk/openvdb contributors. Licensed under the MIT License (see THIRD_PARTY_NOTICES.md).\n// Changes: TypeScript; the generator is a function (the script that writes ./mie-table.ts is\n// scripts/k3/mie-phase-table.mjs); the table read is an f64 CPU twin. Divergences: DIVERGES.md (K3.4 rows).\n\n/**\n * Lorenz-Mie phase tables of mjurczyk's `'lorenz-mie'` / `'lorenz-mie-rgb'` phase functions (K3.4,\n * R1 §5 and §7): cumulus water droplets (Deirmendjian C1, n(r) = r⁶ e^(−1.5 r), r in µm), the Mie\n * series after Bohren & Huffman's BHMIE, absorption ignored. Each table is the phase divided by the\n * isotropic phase 1/(4π) at 2048 angles θ = π u² (dense near the forward peak). The committed tables\n * (`./mie-table.ts`) are this generator's output (`scripts/k3/mie-phase-table.mjs`), not data copied\n * from his repo; the unit test regenerates them.\n */\n\nimport { frameMieRgbTable, frameMieTable, frameMieTableSize } from \"./mie-table.js\";\nimport { vdbFloatToHalf, vdbHalfToFloat } from \"../nanovdb/half.js\";\n\n/** Texels of the tables (his `frameMieTableSize`). */\nexport const vdbFrameMieTableSize = frameMieTableSize;\n\n/** Asymmetry g of the 'lorenz-mie' table (his `frameMieAsymmetry`; 'lorenz-mie-rgb' uses it too). */\nexport const vdbFrameMieAsymmetry = 0.8526;\n\n/** Lorenz-Mie mode of 'lorenz-mie-rgb' in the phase vector (his `frameMieRgbMode`). */\nexport const vdbFrameMieRgbMode = 2.0;\n\n/** The channels of 'lorenz-mie-rgb': wavelength (µm) and the refractive index of water there. */\nexport const vdbFrameMieRgbChannels: readonly { name: string; wavelength: number; refractiveIndex: number }[] = [\n { name: \"Red\", wavelength: 0.65, refractiveIndex: 1.3311 },\n { name: \"Green\", wavelength: 0.55, refractiveIndex: 1.3335 },\n { name: \"Blue\", wavelength: 0.45, refractiveIndex: 1.3374 },\n];\n\n/** 'lorenz-mie': 550 nm, n = 1.335. */\nexport const vdbFrameMieChannel = { wavelength: 0.55, refractiveIndex: 1.335 } as const;\n\nexport interface VDBFrameMieTableOptions {\n /** Table texels (2048). */\n tableSize?: number;\n /** Droplet radius range (µm) and trapezoid steps (0.05–30, 1200). */\n radiusMin?: number;\n radiusMax?: number;\n radiusSteps?: number;\n}\n\nexport interface VDBFrameMieTableResult {\n /** Phase / (1 / 4π) at θ = π u², u = i / (size − 1). */\n table: Float64Array;\n /** Mean cosine of the scattering angle. */\n asymmetry: number;\n /** The forward peak (largest value). */\n peak: number;\n}\n\n/**\n * The droplet-distribution phase table at one wavelength (µm) and refractive index: his\n * `createTable`, f64. About 1–2 s per table at the default size (1201 radii × ~200 terms × 2048 angles).\n */\nexport function vdbFrameMieTable(wavelength: number, refractiveIndex: number, o: VDBFrameMieTableOptions = {}): VDBFrameMieTableResult {\n const tableSize = o.tableSize ?? 2048;\n const radiusMin = o.radiusMin ?? 0.05;\n const radiusMax = o.radiusMax ?? 30.0;\n const radiusSteps = o.radiusSteps ?? 1200;\n const angles = Array.from({ length: tableSize }, (_, index) => {\n const u = index / (tableSize - 1);\n return Math.PI * u * u;\n });\n const cosines = angles.map(Math.cos);\n const intensity = new Float64Array(tableSize);\n\n // (|S1|² + |S2|²) / 2 of one droplet, times weight, added to intensity (BHMIE).\n const addDroplet = (x: number, m: number, weight: number) => {\n const y = m * x;\n const termCount = Math.round(x + 4.0 * Math.cbrt(x) + 2.0);\n const recurrenceCount = Math.round(Math.max(termCount, Math.abs(y))) + 15;\n // Logarithmic derivative D(n), downward recurrence\n const logDerivative = new Float64Array(recurrenceCount + 1);\n for (let n = recurrenceCount; n >= 2; n--) logDerivative[n - 1] = n / y - 1.0 / (logDerivative[n]! + n / y);\n // Riccati-Bessel functions psi and chi, xi = psi − i chi\n let psi0 = Math.cos(x);\n let psi1 = Math.sin(x);\n let chi0 = -Math.sin(x);\n let chi1 = Math.cos(x);\n const aRe = new Float64Array(termCount);\n const aIm = new Float64Array(termCount);\n const bRe = new Float64Array(termCount);\n const bIm = new Float64Array(termCount);\n for (let n = 1; n <= termCount; n++) {\n const psi = ((2 * n - 1) * psi1) / x - psi0;\n const chi = ((2 * n - 1) * chi1) / x - chi0;\n // an = (fa psi − psi1) / (fa xi − xi1), bn the same with fb\n const coefficient = (factor: number, re: Float64Array, im: Float64Array) => {\n const numerator = factor * psi - psi1;\n const denominatorRe = factor * psi - psi1;\n const denominatorIm = -(factor * chi - chi1);\n const scale = denominatorRe * denominatorRe + denominatorIm * denominatorIm;\n re[n - 1] = (numerator * denominatorRe) / scale;\n im[n - 1] = (-numerator * denominatorIm) / scale;\n };\n coefficient(logDerivative[n]! / m + n / x, aRe, aIm);\n coefficient(m * logDerivative[n]! + n / x, bRe, bIm);\n psi0 = psi1;\n psi1 = psi;\n chi0 = chi1;\n chi1 = chi;\n }\n for (let j = 0; j < tableSize; j++) {\n const mu = cosines[j]!;\n let pi0 = 0.0;\n let pi1 = 1.0;\n let s1Re = 0.0;\n let s1Im = 0.0;\n let s2Re = 0.0;\n let s2Im = 0.0;\n for (let n = 1; n <= termCount; n++) {\n const fn = (2 * n + 1) / (n * (n + 1));\n const tau = n * mu * pi1 - (n + 1) * pi0;\n s1Re += fn * (aRe[n - 1]! * pi1 + bRe[n - 1]! * tau);\n s1Im += fn * (aIm[n - 1]! * pi1 + bIm[n - 1]! * tau);\n s2Re += fn * (aRe[n - 1]! * tau + bRe[n - 1]! * pi1);\n s2Im += fn * (aIm[n - 1]! * tau + bIm[n - 1]! * pi1);\n const pi = ((2 * n + 1) / n) * mu * pi1 - ((n + 1) / n) * pi0;\n pi0 = pi1;\n pi1 = pi;\n }\n intensity[j] = intensity[j]! + weight * 0.5 * (s1Re * s1Re + s1Im * s1Im + s2Re * s2Re + s2Im * s2Im);\n }\n };\n\n // Normalize to the isotropic phase: the integral over the sphere is 4π, isotropic is 1 (trapezoids in θ).\n const sphereIntegral = (values: ArrayLike<number>) => {\n let sum = 0.0;\n for (let j = 1; j < tableSize; j++) {\n const left = values[j - 1]! * Math.sin(angles[j - 1]!);\n const right = values[j]! * Math.sin(angles[j]!);\n sum += 0.5 * (left + right) * (angles[j]! - angles[j - 1]!);\n }\n return 2.0 * Math.PI * sum;\n };\n\n const radiusStep = (radiusMax - radiusMin) / radiusSteps;\n for (let i = 0; i <= radiusSteps; i++) {\n const radius = radiusMin + i * radiusStep;\n // Trapezoid rule over the radius, n(r) = r⁶ exp(−1.5 r)\n const weight = radius ** 6 * Math.exp(-1.5 * radius) * radiusStep * (i === 0 || i === radiusSteps ? 0.5 : 1.0);\n addDroplet((2.0 * Math.PI * radius) / wavelength, refractiveIndex, weight);\n }\n\n const scale = (4.0 * Math.PI) / sphereIntegral(intensity);\n const table = new Float64Array(tableSize);\n let peak = -Infinity;\n for (let j = 0; j < tableSize; j++) {\n table[j] = intensity[j]! * scale;\n peak = Math.max(peak, table[j]!);\n }\n const asymmetry = sphereIntegral(Array.from(table, (v, j) => v * cosines[j]!)) / (4.0 * Math.PI);\n return { table, asymmetry, peak };\n}\n\n/** His table number format: 6 significant digits. */\nexport const vdbFrameMieFormat = (value: number): number => Number(value.toPrecision(6));\n\n/**\n * Texels of the Lorenz-Mie texture (his `getFrameMieTexels`): the 'lorenz-mie-rgb' tables in red,\n * green, blue and the 'lorenz-mie' table in alpha (one texture keeps the shaders under 16 textures).\n */\nexport function vdbFrameMieTexels(): Float32Array {\n const texels = new Float32Array(frameMieTableSize * 4);\n for (let i = 0; i < frameMieTableSize; i++) {\n texels[i * 4] = frameMieRgbTable[i * 3]!;\n texels[i * 4 + 1] = frameMieRgbTable[i * 3 + 1]!;\n texels[i * 4 + 2] = frameMieRgbTable[i * 3 + 2]!;\n texels[i * 4 + 3] = frameMieTable[i]!;\n }\n return texels;\n}\n\nlet defaultTexels: Float32Array | null = null;\n\n/**\n * frameMieTexel: the table texel pair at the angle of `cosTheta` (u = √(θ/π), texel u (N − 1),\n * `load` of index and index + 1, linear blend), RGBA = (red, green, blue, 'lorenz-mie').\n */\nexport function vdbFrameMieTexel(cosTheta: number, texels?: Float32Array): [number, number, number, number] {\n const t = texels ?? (defaultTexels ??= vdbFrameMieTexels());\n const u = Math.sqrt(Math.acos(Math.min(1, Math.max(-1, cosTheta))) / Math.PI);\n const texel = u * (frameMieTableSize - 1);\n const index = Math.min(Math.trunc(texel), frameMieTableSize - 2);\n const f = texel - index;\n const out: [number, number, number, number] = [0, 0, 0, 0];\n for (let c = 0; c < 4; c++) {\n const a = t[index * 4 + c]!;\n const b = t[(index + 1) * 4 + c]!;\n out[c] = a + (b - a) * f;\n }\n return out;\n}\n\n/** frameMiePhase: the 'lorenz-mie' phase / isotropic at cos θ. */\nexport const vdbFrameMiePhase = (cosTheta: number): number => vdbFrameMieTexel(cosTheta)[3];\n\n/** frameMieRgbPhase: the 'lorenz-mie-rgb' phases / isotropic of the three channels. */\nexport const vdbFrameMieRgbPhase = (cosTheta: number): [number, number, number] => {\n const t = vdbFrameMieTexel(cosTheta);\n return [t[0], t[1], t[2]];\n};\n\n/**\n * K6.3: the Lorenz-Mie texels as the core renderer binds them: binary16, two texels per uniform `vec4u` (texel i's rgba at\n * halves 4i … 4i + 3), 16,384 bytes — a uniform buffer (group 0 binding 4) instead of a sampled texture, so the 'frame'\n * gather keeps its sampled-texture headroom (K6.5b) and compat's 16 KiB uniform limit holds. `texels` (f32) are\n * {@link vdbFrameMieTexelsHalf}, the values the GPU reads (each rounded to binary16, nearest even).\n */\nexport function vdbFrameMieLutWords(): Uint32Array {\n const t = vdbFrameMieTexels();\n const words = new Uint32Array(t.length / 2);\n for (let i = 0; i < words.length; i++) words[i] = vdbFloatToHalf(t[2 * i]!) | (vdbFloatToHalf(t[2 * i + 1]!) << 16);\n return words;\n}\n\n/** The Lorenz-Mie texels rounded to binary16, as the core reads them (pass to {@link vdbFrameMieTexel} in twins). */\nexport function vdbFrameMieTexelsHalf(): Float32Array {\n return Float32Array.from(vdbFrameMieTexels(), (v) => vdbHalfToFloat(vdbFloatToHalf(v)));\n}\n"]}
@@ -0,0 +1,36 @@
1
+ import { type VDBFrameMlp } from "./mlp.js";
2
+ /** A network in `@pathtracer/mlp`'s convention (its `MlpShape` and flat weights), with where our inputs sit. */
3
+ export interface VDBFrameMlpNn {
4
+ /** `@pathtracer/mlp`'s `MlpShape`: `hidden` ReLU layers of `width`, then a linear layer to `outputs`. */
5
+ shape: {
6
+ inputs: number;
7
+ width: number;
8
+ hidden: number;
9
+ outputs: number;
10
+ };
11
+ /** Layer by layer, row-major [out][in], no biases (`layerOffset` order). */
12
+ weights: Float32Array;
13
+ /** Inputs 0 … features − 1 are our feature vector (3 L + 2 values). */
14
+ features: number;
15
+ /** Inputs that hold a constant 1 (the bias inputs); every other input past `features` is 0. */
16
+ ones: number[];
17
+ }
18
+ /** The weight count of a network in the convention (`@pathtracer/mlp` `weightCount`). */
19
+ export declare function vdbFrameMlpNnWeightCount(shape: VDBFrameMlpNn["shape"]): number;
20
+ /**
21
+ * Our network in `@pathtracer/mlp`'s bias-free convention (exact; module comment). Needs ReLU hidden layers and a
22
+ * linear last layer (the convention has no other activations). The output transform is not carried.
23
+ */
24
+ export declare function vdbFrameMlpToNn(mlp: VDBFrameMlp): VDBFrameMlpNn;
25
+ /** The convention's input vector for our features: the features, 1 at each `ones` input, 0 elsewhere. */
26
+ export declare function vdbFrameMlpNnInputs(nn: Pick<VDBFrameMlpNn, "shape" | "features" | "ones">, features: ArrayLike<number>): Float32Array;
27
+ /**
28
+ * A network in `@pathtracer/mlp`'s convention as ours (exact): the first layer's `ones` columns summed into its
29
+ * biases (other inputs past `features` are zero and dropped), then every hidden unit with no input weights folded into
30
+ * the next layer's biases as the constant relu(its bias) and removed (carriers and dead units).
31
+ */
32
+ export declare function vdbFrameMlpFromNn(nn: VDBFrameMlpNn, o?: {
33
+ name?: string;
34
+ output?: VDBFrameMlp["output"];
35
+ levels?: number;
36
+ }): VDBFrameMlp;
@@ -0,0 +1,159 @@
1
+ // K6.Nc (pmndrs/vdb#3): our code (MIT). It writes the weight convention of pmndrs/pathtracer's `@pathtracer/mlp`
2
+ // (research track N, MIT, Copyright (c) 2026 Dennis Smolek; read at 06488fa, same code as 0e4435b): `config.ts` (layer
3
+ // shapes, `layerOffset`) and `oracle.ts` (`forward`: no biases, hidden ReLU, last layer linear). No code is taken from
4
+ // it. Divergences: DIVERGES.md (K6.Nc row).
5
+ /**
6
+ * K6.Nc: the 'neural' network in the weight convention of the pmndrs neural radiance cache (`@pathtracer/mlp`, the
7
+ * network pmndrs/pathtracer's NRC and pmndrs/gi's neural tail train on the GPU). That convention has **no biases**: a
8
+ * network is `{ inputs, width, hidden, outputs }` (inputs and width multiples of 8, every hidden layer `width` wide),
9
+ * its weights one flat f32 array, layer by layer, each row-major [out][in]; hidden layers are ReLU, the last is linear,
10
+ * and the input encoding carries constant-one inputs that act as the bias (`NrcCache.loadWeights` takes such an array).
11
+ *
12
+ * Ours has biases, so {@link vdbFrameMlpToNn} embeds it exactly: input `features` (our 3 L + 2 features come first)
13
+ * holds a constant 1, and the last unit of every hidden layer is a **carrier** fed only by that one (weight 1, so it
14
+ * stays 1 through each ReLU); each layer's biases become its weights from the one or the carrier. Our 20 → 32 → 32 → 1
15
+ * becomes 24 → 2 × 40 → 1 (2 600 weights; ours 1 761 with biases). {@link vdbFrameMlpFromNn} is the inverse for any
16
+ * network in that convention: the constant-one columns of the first layer become its biases, then every hidden unit
17
+ * with no input weights (a carrier, or a dead unit) is a constant and is folded into the next layer's biases and
18
+ * removed. Ours → convention → ours gives back the same weights bit for bit. The output transform (our 'exp') is not
19
+ * part of the convention: it stays an option, as in the `.tza` map (`mlp-tza.ts`).
20
+ */
21
+ import { VDBToolsError } from "../errors.js";
22
+ import { vdbFrameMlpCheck, vdbFrameMlpOffsets } from "./mlp.js";
23
+ const bad = (message) => {
24
+ throw new VDBToolsError("VDB_BAD_OPTION", `mlp (nn convention): ${message}`);
25
+ };
26
+ const ceil8 = (n) => Math.ceil(n / 8) * 8;
27
+ /** The weight count of a network in the convention (`@pathtracer/mlp` `weightCount`). */
28
+ export function vdbFrameMlpNnWeightCount(shape) {
29
+ return shape.inputs * shape.width + (shape.hidden - 1) * shape.width * shape.width + shape.width * shape.outputs;
30
+ }
31
+ /**
32
+ * Our network in `@pathtracer/mlp`'s bias-free convention (exact; module comment). Needs ReLU hidden layers and a
33
+ * linear last layer (the convention has no other activations). The output transform is not carried.
34
+ */
35
+ export function vdbFrameMlpToNn(mlp) {
36
+ const reason = vdbFrameMlpCheck(mlp);
37
+ if (reason)
38
+ bad(reason);
39
+ const layers = mlp.layers;
40
+ if (layers.length < 2)
41
+ bad("needs at least one hidden layer");
42
+ layers.forEach((l, i) => {
43
+ const want = i === layers.length - 1 ? "linear" : "relu";
44
+ if (l.activation !== want)
45
+ bad(`layer ${i} is ${l.activation}; the convention has ReLU hidden layers and a linear last layer`);
46
+ });
47
+ const features = layers[0].inputs;
48
+ const hidden = layers.length - 1;
49
+ const inputs = ceil8(features + 1);
50
+ const width = ceil8(Math.max(...layers.slice(0, hidden).map((l) => l.outputs)) + 1);
51
+ const outputs = layers[hidden].outputs;
52
+ if (outputs > width)
53
+ bad(`${outputs} outputs exceed the hidden width ${width}`);
54
+ const shape = { inputs, width, hidden, outputs };
55
+ const carrier = width - 1;
56
+ const w = new Float32Array(vdbFrameMlpNnWeightCount(shape));
57
+ const offsets = vdbFrameMlpOffsets(mlp);
58
+ let at = 0;
59
+ for (let li = 0; li <= hidden; li++) {
60
+ const l = layers[li];
61
+ const src = offsets[li];
62
+ const nIn = li === 0 ? inputs : width;
63
+ const nOut = li === hidden ? outputs : width;
64
+ // the bias input: our constant one (layer 0) or the previous layer's carrier
65
+ const one = li === 0 ? features : carrier;
66
+ for (let j = 0; j < l.outputs; j++) {
67
+ for (let i = 0; i < l.inputs; i++)
68
+ w[at + j * nIn + i] = mlp.weights[src + j * l.inputs + i];
69
+ w[at + j * nIn + one] = mlp.weights[src + l.outputs * l.inputs + j];
70
+ }
71
+ if (li < hidden)
72
+ w[at + carrier * nIn + one] = 1;
73
+ at += nIn * nOut;
74
+ }
75
+ return { shape, weights: w, features, ones: [features] };
76
+ }
77
+ /** The convention's input vector for our features: the features, 1 at each `ones` input, 0 elsewhere. */
78
+ export function vdbFrameMlpNnInputs(nn, features) {
79
+ if (features.length !== nn.features)
80
+ bad(`expected ${nn.features} features, got ${features.length}`);
81
+ const x = new Float32Array(nn.shape.inputs);
82
+ for (let i = 0; i < nn.features; i++)
83
+ x[i] = features[i];
84
+ for (const c of nn.ones)
85
+ x[c] = 1;
86
+ return x;
87
+ }
88
+ /**
89
+ * A network in `@pathtracer/mlp`'s convention as ours (exact): the first layer's `ones` columns summed into its
90
+ * biases (other inputs past `features` are zero and dropped), then every hidden unit with no input weights folded into
91
+ * the next layer's biases as the constant relu(its bias) and removed (carriers and dead units).
92
+ */
93
+ export function vdbFrameMlpFromNn(nn, o = {}) {
94
+ const { shape, features, ones } = nn;
95
+ for (const [k, v] of Object.entries(shape))
96
+ if (!Number.isInteger(v) || v < 1)
97
+ bad(`shape.${k} must be a positive integer (got ${v})`);
98
+ if (nn.weights.length !== vdbFrameMlpNnWeightCount(shape))
99
+ bad(`expected ${vdbFrameMlpNnWeightCount(shape)} weights, got ${nn.weights.length}`);
100
+ if (!(features >= 1 && features <= shape.inputs))
101
+ bad(`features must be 1 to ${shape.inputs} (got ${features})`);
102
+ for (const c of ones)
103
+ if (!(Number.isInteger(c) && c >= features && c < shape.inputs))
104
+ bad(`a constant-one input must be past the features (got ${c})`);
105
+ // dense f64 layers: W [out][in] and b [out]
106
+ const W = [];
107
+ const B = [];
108
+ let at = 0;
109
+ for (let l = 0; l <= shape.hidden; l++) {
110
+ const nIn = l === 0 ? shape.inputs : shape.width;
111
+ const nOut = l === shape.hidden ? shape.outputs : shape.width;
112
+ const rows = [];
113
+ const b = new Float64Array(nOut);
114
+ for (let j = 0; j < nOut; j++) {
115
+ const row = Float64Array.from(nn.weights.subarray(at + j * nIn, at + (j + 1) * nIn));
116
+ if (l === 0) {
117
+ for (const c of ones)
118
+ b[j] += row[c];
119
+ rows.push(row.slice(0, features));
120
+ }
121
+ else
122
+ rows.push(row);
123
+ }
124
+ W.push(rows);
125
+ B.push(b);
126
+ at += nIn * nOut;
127
+ }
128
+ // fold the constant hidden units (no input weights) into the next layer, last unit first so indices stay valid
129
+ for (let l = 0; l < shape.hidden; l++) {
130
+ for (let j = W[l].length - 1; j >= 0; j--) {
131
+ if (W[l][j].some((v) => v !== 0))
132
+ continue;
133
+ const k = Math.max(B[l][j], 0);
134
+ const next = W[l + 1];
135
+ next.forEach((row, r) => {
136
+ if (k !== 0)
137
+ B[l + 1][r] += row[j] * k;
138
+ W[l + 1][r] = Float64Array.from([...row.subarray(0, j), ...row.subarray(j + 1)]);
139
+ });
140
+ W[l].splice(j, 1);
141
+ B[l] = Float64Array.from([...B[l].subarray(0, j), ...B[l].subarray(j + 1)]);
142
+ }
143
+ if (W[l].length === 0)
144
+ bad(`hidden layer ${l} has no unit that depends on the inputs`);
145
+ }
146
+ const layers = W.map((rows, l) => ({ inputs: l === 0 ? features : W[l - 1].length, outputs: rows.length, activation: l === shape.hidden ? "linear" : "relu" }));
147
+ const weights = [];
148
+ W.forEach((rows, l) => {
149
+ for (const row of rows)
150
+ weights.push(...row);
151
+ weights.push(...B[l]);
152
+ });
153
+ const mlp = { name: o.name ?? "nn", levels: o.levels ?? (features - 2) / 3, layers, output: o.output ?? "exp", weights: Float32Array.from(weights) };
154
+ const reason = vdbFrameMlpCheck(mlp);
155
+ if (reason)
156
+ bad(reason);
157
+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G,CAAC,CAAC;QAC7C,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAE,CAAC,CAAC;IACzB,CAAC,CAAC,CAAC;IACH,MAAM,GAAG,GAAgB,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,IAAI,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,IAAI,KAAK,EAAE,OAAO,EAAE,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;IAClK,MAAM,MAAM,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACrC,IAAI,MAAM;QAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACxB,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["// K6.Nc (pmndrs/vdb#3): our code (MIT). It writes the weight convention of pmndrs/pathtracer's `@pathtracer/mlp`\n// (research track N, MIT, Copyright (c) 2026 Dennis Smolek; read at 06488fa, same code as 0e4435b): `config.ts` (layer\n// shapes, `layerOffset`) and `oracle.ts` (`forward`: no biases, hidden ReLU, last layer linear). No code is taken from\n// it. Divergences: DIVERGES.md (K6.Nc row).\n\n/**\n * K6.Nc: the 'neural' network in the weight convention of the pmndrs neural radiance cache (`@pathtracer/mlp`, the\n * network pmndrs/pathtracer's NRC and pmndrs/gi's neural tail train on the GPU). That convention has **no biases**: a\n * network is `{ inputs, width, hidden, outputs }` (inputs and width multiples of 8, every hidden layer `width` wide),\n * its weights one flat f32 array, layer by layer, each row-major [out][in]; hidden layers are ReLU, the last is linear,\n * and the input encoding carries constant-one inputs that act as the bias (`NrcCache.loadWeights` takes such an array).\n *\n * Ours has biases, so {@link vdbFrameMlpToNn} embeds it exactly: input `features` (our 3 L + 2 features come first)\n * holds a constant 1, and the last unit of every hidden layer is a **carrier** fed only by that one (weight 1, so it\n * stays 1 through each ReLU); each layer's biases become its weights from the one or the carrier. Our 20 → 32 → 32 → 1\n * becomes 24 → 2 × 40 → 1 (2 600 weights; ours 1 761 with biases). {@link vdbFrameMlpFromNn} is the inverse for any\n * network in that convention: the constant-one columns of the first layer become its biases, then every hidden unit\n * with no input weights (a carrier, or a dead unit) is a constant and is folded into the next layer's biases and\n * removed. Ours → convention → ours gives back the same weights bit for bit. The output transform (our 'exp') is not\n * part of the convention: it stays an option, as in the `.tza` map (`mlp-tza.ts`).\n */\n\nimport { VDBToolsError } from \"../errors.js\";\nimport { vdbFrameMlpCheck, vdbFrameMlpOffsets, type VDBFrameMlp, type VDBFrameMlpLayer } from \"./mlp.js\";\n\n/** A network in `@pathtracer/mlp`'s convention (its `MlpShape` and flat weights), with where our inputs sit. */\nexport interface VDBFrameMlpNn {\n /** `@pathtracer/mlp`'s `MlpShape`: `hidden` ReLU layers of `width`, then a linear layer to `outputs`. */\n shape: { inputs: number; width: number; hidden: number; outputs: number };\n /** Layer by layer, row-major [out][in], no biases (`layerOffset` order). */\n weights: Float32Array;\n /** Inputs 0 … features − 1 are our feature vector (3 L + 2 values). */\n features: number;\n /** Inputs that hold a constant 1 (the bias inputs); every other input past `features` is 0. */\n ones: number[];\n}\n\nconst bad = (message: string): never => {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", `mlp (nn convention): ${message}`);\n};\n\nconst ceil8 = (n: number) => Math.ceil(n / 8) * 8;\n\n/** The weight count of a network in the convention (`@pathtracer/mlp` `weightCount`). */\nexport function vdbFrameMlpNnWeightCount(shape: VDBFrameMlpNn[\"shape\"]): number {\n return shape.inputs * shape.width + (shape.hidden - 1) * shape.width * shape.width + shape.width * shape.outputs;\n}\n\n/**\n * Our network in `@pathtracer/mlp`'s bias-free convention (exact; module comment). Needs ReLU hidden layers and a\n * linear last layer (the convention has no other activations). The output transform is not carried.\n */\nexport function vdbFrameMlpToNn(mlp: VDBFrameMlp): VDBFrameMlpNn {\n const reason = vdbFrameMlpCheck(mlp);\n if (reason) bad(reason);\n const layers = mlp.layers;\n if (layers.length < 2) bad(\"needs at least one hidden layer\");\n layers.forEach((l, i) => {\n const want = i === layers.length - 1 ? \"linear\" : \"relu\";\n if (l.activation !== want) bad(`layer ${i} is ${l.activation}; the convention has ReLU hidden layers and a linear last layer`);\n });\n const features = layers[0]!.inputs;\n const hidden = layers.length - 1;\n const inputs = ceil8(features + 1);\n const width = ceil8(Math.max(...layers.slice(0, hidden).map((l) => l.outputs)) + 1);\n const outputs = layers[hidden]!.outputs;\n if (outputs > width) bad(`${outputs} outputs exceed the hidden width ${width}`);\n const shape = { inputs, width, hidden, outputs };\n const carrier = width - 1;\n const w = new Float32Array(vdbFrameMlpNnWeightCount(shape));\n const offsets = vdbFrameMlpOffsets(mlp);\n let at = 0;\n for (let li = 0; li <= hidden; li++) {\n const l = layers[li]!;\n const src = offsets[li]!;\n const nIn = li === 0 ? inputs : width;\n const nOut = li === hidden ? outputs : width;\n // the bias input: our constant one (layer 0) or the previous layer's carrier\n const one = li === 0 ? features : carrier;\n for (let j = 0; j < l.outputs; j++) {\n for (let i = 0; i < l.inputs; i++) w[at + j * nIn + i] = mlp.weights[src + j * l.inputs + i]!;\n w[at + j * nIn + one] = mlp.weights[src + l.outputs * l.inputs + j]!;\n }\n if (li < hidden) w[at + carrier * nIn + one] = 1;\n at += nIn * nOut;\n }\n return { shape, weights: w, features, ones: [features] };\n}\n\n/** The convention's input vector for our features: the features, 1 at each `ones` input, 0 elsewhere. */\nexport function vdbFrameMlpNnInputs(nn: Pick<VDBFrameMlpNn, \"shape\" | \"features\" | \"ones\">, features: ArrayLike<number>): Float32Array {\n if (features.length !== nn.features) bad(`expected ${nn.features} features, got ${features.length}`);\n const x = new Float32Array(nn.shape.inputs);\n for (let i = 0; i < nn.features; i++) x[i] = features[i]!;\n for (const c of nn.ones) x[c] = 1;\n return x;\n}\n\n/**\n * A network in `@pathtracer/mlp`'s convention as ours (exact): the first layer's `ones` columns summed into its\n * biases (other inputs past `features` are zero and dropped), then every hidden unit with no input weights folded into\n * the next layer's biases as the constant relu(its bias) and removed (carriers and dead units).\n */\nexport function vdbFrameMlpFromNn(nn: VDBFrameMlpNn, o: { name?: string; output?: VDBFrameMlp[\"output\"]; levels?: number } = {}): VDBFrameMlp {\n const { shape, features, ones } = nn;\n for (const [k, v] of Object.entries(shape)) if (!Number.isInteger(v) || v < 1) bad(`shape.${k} must be a positive integer (got ${v})`);\n if (nn.weights.length !== vdbFrameMlpNnWeightCount(shape)) bad(`expected ${vdbFrameMlpNnWeightCount(shape)} weights, got ${nn.weights.length}`);\n if (!(features >= 1 && features <= shape.inputs)) bad(`features must be 1 to ${shape.inputs} (got ${features})`);\n for (const c of ones) if (!(Number.isInteger(c) && c >= features && c < shape.inputs)) bad(`a constant-one input must be past the features (got ${c})`);\n // dense f64 layers: W [out][in] and b [out]\n const W: Float64Array[][] = [];\n const B: Float64Array[] = [];\n let at = 0;\n for (let l = 0; l <= shape.hidden; l++) {\n const nIn = l === 0 ? shape.inputs : shape.width;\n const nOut = l === shape.hidden ? shape.outputs : shape.width;\n const rows: Float64Array[] = [];\n const b = new Float64Array(nOut);\n for (let j = 0; j < nOut; j++) {\n const row = Float64Array.from(nn.weights.subarray(at + j * nIn, at + (j + 1) * nIn));\n if (l === 0) {\n for (const c of ones) b[j]! += row[c]!;\n rows.push(row.slice(0, features));\n } else rows.push(row);\n }\n W.push(rows);\n B.push(b);\n at += nIn * nOut;\n }\n // fold the constant hidden units (no input weights) into the next layer, last unit first so indices stay valid\n for (let l = 0; l < shape.hidden; l++) {\n for (let j = W[l]!.length - 1; j >= 0; j--) {\n if (W[l]![j]!.some((v) => v !== 0)) continue;\n const k = Math.max(B[l]![j]!, 0);\n const next = W[l + 1]!;\n next.forEach((row, r) => {\n if (k !== 0) B[l + 1]![r]! += row[j]! * k;\n W[l + 1]![r] = Float64Array.from([...row.subarray(0, j), ...row.subarray(j + 1)]);\n });\n W[l]!.splice(j, 1);\n B[l] = Float64Array.from([...B[l]!.subarray(0, j), ...B[l]!.subarray(j + 1)]);\n }\n if (W[l]!.length === 0) bad(`hidden layer ${l} has no unit that depends on the inputs`);\n }\n const layers: VDBFrameMlpLayer[] = W.map((rows, l) => ({ inputs: l === 0 ? features : W[l - 1]!.length, outputs: rows.length, activation: l === shape.hidden ? \"linear\" : \"relu\" }));\n const weights: number[] = [];\n W.forEach((rows, l) => {\n for (const row of rows) weights.push(...row);\n weights.push(...B[l]!);\n });\n const mlp: VDBFrameMlp = { name: o.name ?? \"nn\", levels: o.levels ?? (features - 2) / 3, layers, output: o.output ?? \"exp\", weights: Float32Array.from(weights) };\n const reason = vdbFrameMlpCheck(mlp);\n if (reason) bad(reason);\n return mlp;\n}\n"]}
@@ -0,0 +1,29 @@
1
+ import { type VDBFrameMlp } from "./mlp.js";
2
+ /** One tensor of a `.tza` blob (f32 values; f16 tensors are widened on read). */
3
+ export interface VDBTzaTensor {
4
+ data: Float32Array;
5
+ shape: number[];
6
+ /** The layout string (one char per dimension, e.g. "oi"); "" when the blob has none. */
7
+ layout: string;
8
+ /** The stored type: 'f' f32, 'h' f16. */
9
+ type: "f" | "h";
10
+ }
11
+ /** Reads a `.tza` v2 blob (the format `parseTZA` reads): tensor name → tensor, in file order. */
12
+ export declare function vdbTzaRead(bytes: ArrayBuffer | Uint8Array): Map<string, VDBTzaTensor>;
13
+ /** Writes tensors as a `.tza` v2 blob (data 64-byte aligned after the 12-byte header, then the table). */
14
+ export declare function vdbTzaWrite(tensors: ReadonlyMap<string, Pick<VDBTzaTensor, "data" | "shape"> & Partial<Pick<VDBTzaTensor, "layout" | "type">>>): Uint8Array;
15
+ /**
16
+ * K6.Na: a network as `.tza` tensors (`layers.<i>.weight` [outputs, inputs], `layers.<i>.bias` [outputs]). `type` 'h'
17
+ * stores binary16 (half the bytes; the weights round to f16, which changes the network: an A/B, not a format detail).
18
+ * Only networks whose hidden layers are ReLU and whose last layer is linear map onto the convention.
19
+ */
20
+ export declare function vdbFrameMlpToTza(mlp: VDBFrameMlp, o?: {
21
+ type?: "f" | "h";
22
+ }): Uint8Array;
23
+ /** K6.Na: the network of a `.tza` blob written by {@link vdbFrameMlpToTza} (or any `layers.<i>.weight/bias` set). */
24
+ export declare function vdbFrameMlpFromTza(bytes: ArrayBuffer | Uint8Array, o?: {
25
+ name?: string;
26
+ output?: VDBFrameMlp["output"];
27
+ levels?: number;
28
+ extra?: VDBFrameMlp["extra"];
29
+ }): VDBFrameMlp;
@@ -0,0 +1,186 @@
1
+ // Portions derived from pmndrs/denoiser (MIT, Copyright (c) 2024 Dennis Smolek), commit 3ad5e98:
2
+ // packages/denoiser-core/src/tza.ts (`parseTZA`, `halfToFloat`: the OIDN TZA v2 weight container reader).
3
+ // Changes: a writer (the reader's inverse; binary16 through tools/nanovdb/half.ts), errors as VDBToolsError, and the
4
+ // map between a TZA tensor set and the core's generic MLP (`VDBFrameMlp`). Divergences: DIVERGES.md (K6.Na rows).
5
+ /**
6
+ * K6.Na: the 'neural' network in the weight container of the pmndrs neural tooling (pmndrs/denoiser reads Intel OIDN's
7
+ * `.tza` blobs with `parseTZA`, its Python converter with `tza.py`). A `.tza` is a list of named tensors (f32 'f' or
8
+ * f16 'h', any shape); a network is stored as PyTorch `nn.Linear` names: `layers.<i>.weight` [outputs, inputs] (row-major,
9
+ * layout "oi") and `layers.<i>.bias` [outputs] ("o"). Hidden layers are ReLU and the last is linear (the trainer's net);
10
+ * the output transform and the feature levels are not in the file: `levels` = (inputs − 2) / 3, `output` defaults to
11
+ * 'exp' (both options). Our weights stay a TypeScript data module too (the default network needs no fetch).
12
+ */
13
+ import { VDBToolsError } from "../errors.js";
14
+ import { vdbFloatToHalf, vdbHalfToFloat } from "../nanovdb/half.js";
15
+ import { vdbFrameMlpExtraInputs } from "./mlp.js";
16
+ const MAGIC = 0x41d7;
17
+ const MAJOR_VERSION = 2;
18
+ /** Tensor data alignment of the writer (OIDN's blobs align tensors to 64 bytes). */
19
+ const ALIGN = 64;
20
+ const bad = (message) => {
21
+ throw new VDBToolsError("VDB_BAD_OPTION", `tza: ${message}`);
22
+ };
23
+ /** Reads a `.tza` v2 blob (the format `parseTZA` reads): tensor name → tensor, in file order. */
24
+ export function vdbTzaRead(bytes) {
25
+ const buf = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
26
+ if (buf.byteLength < 12)
27
+ bad("too short for a header");
28
+ const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
29
+ if (view.getUint16(0, true) !== MAGIC)
30
+ bad("invalid or corrupted weights blob (magic)");
31
+ const major = view.getUint8(2);
32
+ if (major !== MAJOR_VERSION)
33
+ bad(`unsupported weights blob version ${major}`);
34
+ let offset = Number(view.getBigUint64(4, true));
35
+ const need = (n) => {
36
+ if (offset + n > buf.byteLength)
37
+ bad("table runs past the end of the blob");
38
+ };
39
+ need(4);
40
+ const count = view.getUint32(offset, true);
41
+ offset += 4;
42
+ const decoder = new TextDecoder();
43
+ const tensors = new Map();
44
+ for (let t = 0; t < count; t++) {
45
+ need(2);
46
+ const nameLength = view.getUint16(offset, true);
47
+ offset += 2;
48
+ need(nameLength + 1);
49
+ const name = decoder.decode(buf.subarray(offset, offset + nameLength));
50
+ offset += nameLength;
51
+ const dims = view.getUint8(offset);
52
+ offset += 1;
53
+ need(dims * 5 + 9);
54
+ const shape = [];
55
+ for (let d = 0; d < dims; d++) {
56
+ shape.push(view.getUint32(offset, true));
57
+ offset += 4;
58
+ }
59
+ const layout = decoder.decode(buf.subarray(offset, offset + dims));
60
+ offset += dims;
61
+ const type = String.fromCharCode(view.getUint8(offset));
62
+ offset += 1;
63
+ const at = Number(view.getBigUint64(offset, true));
64
+ offset += 8;
65
+ const n = shape.reduce((a, b) => a * b, 1);
66
+ if (type !== "f" && type !== "h")
67
+ bad(`tensor ${name}: invalid data type '${type}'`);
68
+ const size = n * (type === "f" ? 4 : 2);
69
+ if (at + size > buf.byteLength)
70
+ bad(`tensor ${name} runs past the end of the blob`);
71
+ const data = new Float32Array(n);
72
+ for (let i = 0; i < n; i++)
73
+ data[i] = type === "f" ? view.getFloat32(at + 4 * i, true) : vdbHalfToFloat(view.getUint16(at + 2 * i, true));
74
+ tensors.set(name, { data, shape, layout, type: type });
75
+ }
76
+ return tensors;
77
+ }
78
+ /** Writes tensors as a `.tza` v2 blob (data 64-byte aligned after the 12-byte header, then the table). */
79
+ export function vdbTzaWrite(tensors) {
80
+ const encoder = new TextEncoder();
81
+ const entries = [...tensors].map(([name, t]) => {
82
+ const type = t.type ?? "f";
83
+ const n = t.shape.reduce((a, b) => a * b, 1);
84
+ if (n !== t.data.length)
85
+ bad(`tensor ${name}: shape [${t.shape.join(", ")}] holds ${n} values, data has ${t.data.length}`);
86
+ const layout = t.layout ?? "";
87
+ if (layout && layout.length !== t.shape.length)
88
+ bad(`tensor ${name}: layout "${layout}" for ${t.shape.length} dimensions`);
89
+ return { name: encoder.encode(name), shape: t.shape, layout: encoder.encode(layout.padEnd(t.shape.length, "x")), type, data: t.data, bytes: n * (type === "f" ? 4 : 2) };
90
+ });
91
+ let at = 12;
92
+ const placed = entries.map((e) => {
93
+ at = Math.ceil(at / ALIGN) * ALIGN;
94
+ const offset = at;
95
+ at += e.bytes;
96
+ return offset;
97
+ });
98
+ const table = at;
99
+ const tableBytes = 4 + entries.reduce((s, e) => s + 2 + e.name.length + 1 + 5 * e.shape.length + 1 + 8, 0);
100
+ const out = new Uint8Array(table + tableBytes);
101
+ const view = new DataView(out.buffer);
102
+ view.setUint16(0, MAGIC, true);
103
+ view.setUint8(2, MAJOR_VERSION);
104
+ view.setUint8(3, 0);
105
+ view.setBigUint64(4, BigInt(table), true);
106
+ entries.forEach((e, i) => {
107
+ const o = placed[i];
108
+ for (let k = 0; k < e.data.length; k++) {
109
+ if (e.type === "f")
110
+ view.setFloat32(o + 4 * k, e.data[k], true);
111
+ else
112
+ view.setUint16(o + 2 * k, vdbFloatToHalf(e.data[k]), true);
113
+ }
114
+ });
115
+ let p = table;
116
+ view.setUint32(p, entries.length, true);
117
+ p += 4;
118
+ entries.forEach((e, i) => {
119
+ view.setUint16(p, e.name.length, true);
120
+ p += 2;
121
+ out.set(e.name, p);
122
+ p += e.name.length;
123
+ view.setUint8(p, e.shape.length);
124
+ p += 1;
125
+ for (const d of e.shape) {
126
+ view.setUint32(p, d, true);
127
+ p += 4;
128
+ }
129
+ out.set(e.layout, p);
130
+ p += e.shape.length;
131
+ view.setUint8(p, e.type.charCodeAt(0));
132
+ p += 1;
133
+ view.setBigUint64(p, BigInt(placed[i]), true);
134
+ p += 8;
135
+ });
136
+ return out;
137
+ }
138
+ /**
139
+ * K6.Na: a network as `.tza` tensors (`layers.<i>.weight` [outputs, inputs], `layers.<i>.bias` [outputs]). `type` 'h'
140
+ * stores binary16 (half the bytes; the weights round to f16, which changes the network: an A/B, not a format detail).
141
+ * Only networks whose hidden layers are ReLU and whose last layer is linear map onto the convention.
142
+ */
143
+ export function vdbFrameMlpToTza(mlp, o = {}) {
144
+ const tensors = new Map();
145
+ let at = 0;
146
+ mlp.layers.forEach((l, i) => {
147
+ const wanted = i === mlp.layers.length - 1 ? "linear" : "relu";
148
+ if (l.activation !== wanted)
149
+ bad(`layer ${i} is '${l.activation}'; the .tza convention has ReLU hidden layers and a linear last layer`);
150
+ tensors.set(`layers.${i}.weight`, { data: mlp.weights.slice(at, at + l.outputs * l.inputs), shape: [l.outputs, l.inputs], layout: "oi", type: o.type ?? "f" });
151
+ at += l.outputs * l.inputs;
152
+ tensors.set(`layers.${i}.bias`, { data: mlp.weights.slice(at, at + l.outputs), shape: [l.outputs], layout: "o", type: o.type ?? "f" });
153
+ at += l.outputs;
154
+ });
155
+ return vdbTzaWrite(tensors);
156
+ }
157
+ /** K6.Na: the network of a `.tza` blob written by {@link vdbFrameMlpToTza} (or any `layers.<i>.weight/bias` set). */
158
+ export function vdbFrameMlpFromTza(bytes, o = {}) {
159
+ const tensors = vdbTzaRead(bytes);
160
+ const layers = [];
161
+ const parts = [];
162
+ for (let i = 0; tensors.has(`layers.${i}.weight`); i++) {
163
+ const w = tensors.get(`layers.${i}.weight`);
164
+ const b = tensors.get(`layers.${i}.bias`) ?? bad(`layers.${i}.bias is missing`);
165
+ if (w.shape.length !== 2)
166
+ bad(`layers.${i}.weight has ${w.shape.length} dimensions (want [outputs, inputs])`);
167
+ const [outputs, inputs] = w.shape;
168
+ if (b.shape.length !== 1 || b.shape[0] !== outputs)
169
+ bad(`layers.${i}.bias has shape [${b.shape.join(", ")}] (want [${outputs}])`);
170
+ layers.push({ inputs, outputs, activation: "relu" });
171
+ parts.push(w.data, b.data);
172
+ }
173
+ if (layers.length === 0)
174
+ bad("no layers.0.weight tensor");
175
+ layers[layers.length - 1].activation = "linear";
176
+ const weights = new Float32Array(parts.reduce((s, p) => s + p.length, 0));
177
+ let at = 0;
178
+ for (const p of parts) {
179
+ weights.set(p, at);
180
+ at += p.length;
181
+ }
182
+ // K6.Nb: an `extra: 'g'` network has one input after the 3 L + 2 features (the container has no attributes: an option)
183
+ const levels = o.levels ?? (layers[0].inputs - 2 - vdbFrameMlpExtraInputs(o)) / 3;
184
+ return { name: o.name ?? "tza", levels, layers, output: o.output ?? "exp", weights, ...(o.extra ? { extra: o.extra } : {}) };
185
+ }
186
+ //# sourceMappingURL=mlp-tza.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mlp-tza.js","sourceRoot":"","sources":["../../../src/tools/frame/mlp-tza.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,4GAA4G;AAC5G,qHAAqH;AACrH,kHAAkH;AAElH;;;;;;;GAOG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAA2C,MAAM,UAAU,CAAC;AAE3F,MAAM,KAAK,GAAG,MAAM,CAAC;AACrB,MAAM,aAAa,GAAG,CAAC,CAAC;AACxB,oFAAoF;AACpF,MAAM,KAAK,GAAG,EAAE,CAAC;AAYjB,MAAM,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,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;AAC/H,CAAC","sourcesContent":["// Portions derived from pmndrs/denoiser (MIT, Copyright (c) 2024 Dennis Smolek), commit 3ad5e98:\n// packages/denoiser-core/src/tza.ts (`parseTZA`, `halfToFloat`: the OIDN TZA v2 weight container reader).\n// Changes: a writer (the reader's inverse; binary16 through tools/nanovdb/half.ts), errors as VDBToolsError, and the\n// map between a TZA tensor set and the core's generic MLP (`VDBFrameMlp`). Divergences: DIVERGES.md (K6.Na rows).\n\n/**\n * K6.Na: the 'neural' network in the weight container of the pmndrs neural tooling (pmndrs/denoiser reads Intel OIDN's\n * `.tza` blobs with `parseTZA`, its Python converter with `tza.py`). A `.tza` is a list of named tensors (f32 'f' or\n * f16 'h', any shape); a network is stored as PyTorch `nn.Linear` names: `layers.<i>.weight` [outputs, inputs] (row-major,\n * layout \"oi\") and `layers.<i>.bias` [outputs] (\"o\"). Hidden layers are ReLU and the last is linear (the trainer's net);\n * the output transform and the feature levels are not in the file: `levels` = (inputs − 2) / 3, `output` defaults to\n * 'exp' (both options). Our weights stay a TypeScript data module too (the default network needs no fetch).\n */\n\nimport { VDBToolsError } from \"../errors.js\";\nimport { vdbFloatToHalf, vdbHalfToFloat } from \"../nanovdb/half.js\";\nimport { vdbFrameMlpExtraInputs, type VDBFrameMlp, type VDBFrameMlpLayer } from \"./mlp.js\";\n\nconst MAGIC = 0x41d7;\nconst MAJOR_VERSION = 2;\n/** Tensor data alignment of the writer (OIDN's blobs align tensors to 64 bytes). */\nconst ALIGN = 64;\n\n/** One tensor of a `.tza` blob (f32 values; f16 tensors are widened on read). */\nexport interface VDBTzaTensor {\n data: Float32Array;\n shape: number[];\n /** The layout string (one char per dimension, e.g. \"oi\"); \"\" when the blob has none. */\n layout: string;\n /** The stored type: 'f' f32, 'h' f16. */\n type: \"f\" | \"h\";\n}\n\nconst bad = (message: string): never => {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", `tza: ${message}`);\n};\n\n/** Reads a `.tza` v2 blob (the format `parseTZA` reads): tensor name → tensor, in file order. */\nexport function vdbTzaRead(bytes: ArrayBuffer | Uint8Array): Map<string, VDBTzaTensor> {\n const buf = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);\n if (buf.byteLength < 12) bad(\"too short for a header\");\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);\n if (view.getUint16(0, true) !== MAGIC) bad(\"invalid or corrupted weights blob (magic)\");\n const major = view.getUint8(2);\n if (major !== MAJOR_VERSION) bad(`unsupported weights blob version ${major}`);\n let offset = Number(view.getBigUint64(4, true));\n const need = (n: number) => {\n if (offset + n > buf.byteLength) bad(\"table runs past the end of the blob\");\n };\n need(4);\n const count = view.getUint32(offset, true);\n offset += 4;\n const decoder = new TextDecoder();\n const tensors = new Map<string, VDBTzaTensor>();\n for (let t = 0; t < count; t++) {\n need(2);\n const nameLength = view.getUint16(offset, true);\n offset += 2;\n need(nameLength + 1);\n const name = decoder.decode(buf.subarray(offset, offset + nameLength));\n offset += nameLength;\n const dims = view.getUint8(offset);\n offset += 1;\n need(dims * 5 + 9);\n const shape: number[] = [];\n for (let d = 0; d < dims; d++) {\n shape.push(view.getUint32(offset, true));\n offset += 4;\n }\n const layout = decoder.decode(buf.subarray(offset, offset + dims));\n offset += dims;\n const type = String.fromCharCode(view.getUint8(offset));\n offset += 1;\n const at = Number(view.getBigUint64(offset, true));\n offset += 8;\n const n = shape.reduce((a, b) => a * b, 1);\n if (type !== \"f\" && type !== \"h\") bad(`tensor ${name}: invalid data type '${type}'`);\n const size = n * (type === \"f\" ? 4 : 2);\n if (at + size > buf.byteLength) bad(`tensor ${name} runs past the end of the blob`);\n const data = new Float32Array(n);\n for (let i = 0; i < n; i++) data[i] = type === \"f\" ? view.getFloat32(at + 4 * i, true) : vdbHalfToFloat(view.getUint16(at + 2 * i, true));\n tensors.set(name, { data, shape, layout, type: type as \"f\" | \"h\" });\n }\n return tensors;\n}\n\n/** Writes tensors as a `.tza` v2 blob (data 64-byte aligned after the 12-byte header, then the table). */\nexport function vdbTzaWrite(tensors: ReadonlyMap<string, Pick<VDBTzaTensor, \"data\" | \"shape\"> & Partial<Pick<VDBTzaTensor, \"layout\" | \"type\">>>): Uint8Array {\n const encoder = new TextEncoder();\n const entries = [...tensors].map(([name, t]) => {\n const type = t.type ?? \"f\";\n const n = t.shape.reduce((a, b) => a * b, 1);\n if (n !== t.data.length) bad(`tensor ${name}: shape [${t.shape.join(\", \")}] holds ${n} values, data has ${t.data.length}`);\n const layout = t.layout ?? \"\";\n if (layout && layout.length !== t.shape.length) bad(`tensor ${name}: layout \"${layout}\" for ${t.shape.length} dimensions`);\n return { name: encoder.encode(name), shape: t.shape, layout: encoder.encode(layout.padEnd(t.shape.length, \"x\")), type, data: t.data, bytes: n * (type === \"f\" ? 4 : 2) };\n });\n let at = 12;\n const placed = entries.map((e) => {\n at = Math.ceil(at / ALIGN) * ALIGN;\n const offset = at;\n at += e.bytes;\n return offset;\n });\n const table = at;\n const tableBytes = 4 + entries.reduce((s, e) => s + 2 + e.name.length + 1 + 5 * e.shape.length + 1 + 8, 0);\n const out = new Uint8Array(table + tableBytes);\n const view = new DataView(out.buffer);\n view.setUint16(0, MAGIC, true);\n view.setUint8(2, MAJOR_VERSION);\n view.setUint8(3, 0);\n view.setBigUint64(4, BigInt(table), true);\n entries.forEach((e, i) => {\n const o = placed[i]!;\n for (let k = 0; k < e.data.length; k++) {\n if (e.type === \"f\") view.setFloat32(o + 4 * k, e.data[k]!, true);\n else view.setUint16(o + 2 * k, vdbFloatToHalf(e.data[k]!), true);\n }\n });\n let p = table;\n view.setUint32(p, entries.length, true);\n p += 4;\n entries.forEach((e, i) => {\n view.setUint16(p, e.name.length, true);\n p += 2;\n out.set(e.name, p);\n p += e.name.length;\n view.setUint8(p, e.shape.length);\n p += 1;\n for (const d of e.shape) {\n view.setUint32(p, d, true);\n p += 4;\n }\n out.set(e.layout, p);\n p += e.shape.length;\n view.setUint8(p, e.type.charCodeAt(0));\n p += 1;\n view.setBigUint64(p, BigInt(placed[i]!), true);\n p += 8;\n });\n return out;\n}\n\n/**\n * K6.Na: a network as `.tza` tensors (`layers.<i>.weight` [outputs, inputs], `layers.<i>.bias` [outputs]). `type` 'h'\n * stores binary16 (half the bytes; the weights round to f16, which changes the network: an A/B, not a format detail).\n * Only networks whose hidden layers are ReLU and whose last layer is linear map onto the convention.\n */\nexport function vdbFrameMlpToTza(mlp: VDBFrameMlp, o: { type?: \"f\" | \"h\" } = {}): Uint8Array {\n const tensors = new Map<string, Pick<VDBTzaTensor, \"data\" | \"shape\" | \"layout\" | \"type\">>();\n let at = 0;\n mlp.layers.forEach((l, i) => {\n const wanted = i === mlp.layers.length - 1 ? \"linear\" : \"relu\";\n if (l.activation !== wanted) bad(`layer ${i} is '${l.activation}'; the .tza convention has ReLU hidden layers and a linear last layer`);\n tensors.set(`layers.${i}.weight`, { data: mlp.weights.slice(at, at + l.outputs * l.inputs), shape: [l.outputs, l.inputs], layout: \"oi\", type: o.type ?? \"f\" });\n at += l.outputs * l.inputs;\n tensors.set(`layers.${i}.bias`, { data: mlp.weights.slice(at, at + l.outputs), shape: [l.outputs], layout: \"o\", type: o.type ?? \"f\" });\n at += l.outputs;\n });\n return vdbTzaWrite(tensors);\n}\n\n/** K6.Na: the network of a `.tza` blob written by {@link vdbFrameMlpToTza} (or any `layers.<i>.weight/bias` set). */\nexport function vdbFrameMlpFromTza(bytes: ArrayBuffer | Uint8Array, o: { name?: string; output?: VDBFrameMlp[\"output\"]; levels?: number; extra?: VDBFrameMlp[\"extra\"] } = {}): VDBFrameMlp {\n const tensors = vdbTzaRead(bytes);\n const layers: VDBFrameMlpLayer[] = [];\n const parts: Float32Array[] = [];\n for (let i = 0; tensors.has(`layers.${i}.weight`); i++) {\n const w = tensors.get(`layers.${i}.weight`)!;\n const b = tensors.get(`layers.${i}.bias`) ?? bad(`layers.${i}.bias is missing`);\n if (w.shape.length !== 2) bad(`layers.${i}.weight has ${w.shape.length} dimensions (want [outputs, inputs])`);\n const [outputs, inputs] = w.shape as [number, number];\n if (b.shape.length !== 1 || b.shape[0] !== outputs) bad(`layers.${i}.bias has shape [${b.shape.join(\", \")}] (want [${outputs}])`);\n layers.push({ inputs, outputs, activation: \"relu\" });\n parts.push(w.data, b.data);\n }\n if (layers.length === 0) bad(\"no layers.0.weight tensor\");\n layers[layers.length - 1]!.activation = \"linear\";\n const weights = new Float32Array(parts.reduce((s, p) => s + p.length, 0));\n let at = 0;\n for (const p of parts) {\n weights.set(p, at);\n at += p.length;\n }\n // K6.Nb: an `extra: 'g'` network has one input after the 3 L + 2 features (the container has no attributes: an option)\n const levels = o.levels ?? (layers[0]!.inputs - 2 - vdbFrameMlpExtraInputs(o)) / 3;\n return { name: o.name ?? \"tza\", levels, layers, output: o.output ?? \"exp\", weights, ...(o.extra ? { extra: o.extra } : {}) };\n}\n"]}