@pmndrs/vdb 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (390) hide show
  1. package/CHANGELOG.md +137 -0
  2. package/LICENSE +21 -0
  3. package/README.md +448 -2
  4. package/THIRD_PARTY_NOTICES.md +147 -0
  5. package/dist/core/compute/atlas.d.ts +94 -0
  6. package/dist/core/compute/atlas.js +98 -0
  7. package/dist/core/compute/atlas.js.map +1 -0
  8. package/dist/core/compute/index.d.ts +13 -0
  9. package/dist/core/compute/index.js +9 -0
  10. package/dist/core/compute/index.js.map +1 -0
  11. package/dist/core/compute/pyramid.d.ts +105 -0
  12. package/dist/core/compute/pyramid.js +455 -0
  13. package/dist/core/compute/pyramid.js.map +1 -0
  14. package/dist/core/compute/shared.d.ts +115 -0
  15. package/dist/core/compute/shared.js +211 -0
  16. package/dist/core/compute/shared.js.map +1 -0
  17. package/dist/core/compute/stats.d.ts +71 -0
  18. package/dist/core/compute/stats.js +188 -0
  19. package/dist/core/compute/stats.js.map +1 -0
  20. package/dist/core/compute/value-transform.d.ts +23 -0
  21. package/dist/core/compute/value-transform.js +58 -0
  22. package/dist/core/compute/value-transform.js.map +1 -0
  23. package/dist/core/errors.d.ts +11 -0
  24. package/dist/core/errors.js +9 -0
  25. package/dist/core/errors.js.map +1 -0
  26. package/dist/core/index.d.ts +30 -0
  27. package/dist/core/index.js +27 -0
  28. package/dist/core/index.js.map +1 -0
  29. package/dist/core/internal.d.ts +15 -0
  30. package/dist/core/internal.js +15 -0
  31. package/dist/core/internal.js.map +1 -0
  32. package/dist/core/pool/affine.d.ts +34 -0
  33. package/dist/core/pool/affine.js +100 -0
  34. package/dist/core/pool/affine.js.map +1 -0
  35. package/dist/core/pool/allocator.d.ts +32 -0
  36. package/dist/core/pool/allocator.js +81 -0
  37. package/dist/core/pool/allocator.js.map +1 -0
  38. package/dist/core/pool/image-header.d.ts +82 -0
  39. package/dist/core/pool/image-header.js +175 -0
  40. package/dist/core/pool/image-header.js.map +1 -0
  41. package/dist/core/pool/layout.d.ts +164 -0
  42. package/dist/core/pool/layout.js +267 -0
  43. package/dist/core/pool/layout.js.map +1 -0
  44. package/dist/core/pool/limits.d.ts +40 -0
  45. package/dist/core/pool/limits.js +79 -0
  46. package/dist/core/pool/limits.js.map +1 -0
  47. package/dist/core/pool/pool.d.ts +279 -0
  48. package/dist/core/pool/pool.js +953 -0
  49. package/dist/core/pool/pool.js.map +1 -0
  50. package/dist/core/source/dense.d.ts +19 -0
  51. package/dist/core/source/dense.js +287 -0
  52. package/dist/core/source/dense.js.map +1 -0
  53. package/dist/core/source/types.d.ts +63 -0
  54. package/dist/core/source/types.js +9 -0
  55. package/dist/core/source/types.js.map +1 -0
  56. package/dist/core/types.d.ts +28 -0
  57. package/dist/core/types.js +28 -0
  58. package/dist/core/types.js.map +1 -0
  59. package/dist/core/wgsl/api.d.ts +41 -0
  60. package/dist/core/wgsl/api.js +463 -0
  61. package/dist/core/wgsl/api.js.map +1 -0
  62. package/dist/core/wgsl/generate.d.ts +82 -0
  63. package/dist/core/wgsl/generate.js +505 -0
  64. package/dist/core/wgsl/generate.js.map +1 -0
  65. package/dist/core/wgsl/level-set.d.ts +54 -0
  66. package/dist/core/wgsl/level-set.js +194 -0
  67. package/dist/core/wgsl/level-set.js.map +1 -0
  68. package/dist/core/wgsl/pnanovdb.chunks.generated.d.ts +14 -0
  69. package/dist/core/wgsl/pnanovdb.chunks.generated.js +330 -0
  70. package/dist/core/wgsl/pnanovdb.chunks.generated.js.map +1 -0
  71. package/dist/core/wgsl/reserved.d.ts +9 -0
  72. package/dist/core/wgsl/reserved.js +26 -0
  73. package/dist/core/wgsl/reserved.js.map +1 -0
  74. package/dist/core/wgsl/types.d.ts +104 -0
  75. package/dist/core/wgsl/types.js +2 -0
  76. package/dist/core/wgsl/types.js.map +1 -0
  77. package/dist/three/coarse-first.d.ts +162 -0
  78. package/dist/three/coarse-first.js +187 -0
  79. package/dist/three/coarse-first.js.map +1 -0
  80. package/dist/three/compute.d.ts +63 -0
  81. package/dist/three/compute.js +56 -0
  82. package/dist/three/compute.js.map +1 -0
  83. package/dist/three/device.d.ts +59 -0
  84. package/dist/three/device.js +59 -0
  85. package/dist/three/device.js.map +1 -0
  86. package/dist/three/frame/blackbody.d.ts +42 -0
  87. package/dist/three/frame/blackbody.js +74 -0
  88. package/dist/three/frame/blackbody.js.map +1 -0
  89. package/dist/three/frame/chunks.d.ts +157 -0
  90. package/dist/three/frame/chunks.js +559 -0
  91. package/dist/three/frame/chunks.js.map +1 -0
  92. package/dist/three/frame/density-material.d.ts +53 -0
  93. package/dist/three/frame/density-material.js +353 -0
  94. package/dist/three/frame/density-material.js.map +1 -0
  95. package/dist/three/frame/emission-light.d.ts +167 -0
  96. package/dist/three/frame/emission-light.js +655 -0
  97. package/dist/three/frame/emission-light.js.map +1 -0
  98. package/dist/three/frame/environment-grid-material.d.ts +21 -0
  99. package/dist/three/frame/environment-grid-material.js +184 -0
  100. package/dist/three/frame/environment-grid-material.js.map +1 -0
  101. package/dist/three/frame/environment-material.d.ts +22 -0
  102. package/dist/three/frame/environment-material.js +87 -0
  103. package/dist/three/frame/environment-material.js.map +1 -0
  104. package/dist/three/frame/grid-mip-material.d.ts +12 -0
  105. package/dist/three/frame/grid-mip-material.js +61 -0
  106. package/dist/three/frame/grid-mip-material.js.map +1 -0
  107. package/dist/three/frame/index.d.ts +39 -0
  108. package/dist/three/frame/index.js +35 -0
  109. package/dist/three/frame/index.js.map +1 -0
  110. package/dist/three/frame/inject-material.d.ts +56 -0
  111. package/dist/three/frame/inject-material.js +424 -0
  112. package/dist/three/frame/inject-material.js.map +1 -0
  113. package/dist/three/frame/integrate-material.d.ts +26 -0
  114. package/dist/three/frame/integrate-material.js +198 -0
  115. package/dist/three/frame/integrate-material.js.map +1 -0
  116. package/dist/three/frame/layout.d.ts +34 -0
  117. package/dist/three/frame/layout.js +48 -0
  118. package/dist/three/frame/layout.js.map +1 -0
  119. package/dist/three/frame/lighting-material.d.ts +41 -0
  120. package/dist/three/frame/lighting-material.js +257 -0
  121. package/dist/three/frame/lighting-material.js.map +1 -0
  122. package/dist/three/frame/lights.d.ts +11 -0
  123. package/dist/three/frame/lights.js +16 -0
  124. package/dist/three/frame/lights.js.map +1 -0
  125. package/dist/three/frame/medium.d.ts +21 -0
  126. package/dist/three/frame/medium.js +29 -0
  127. package/dist/three/frame/medium.js.map +1 -0
  128. package/dist/three/frame/neural.d.ts +14 -0
  129. package/dist/three/frame/neural.js +105 -0
  130. package/dist/three/frame/neural.js.map +1 -0
  131. package/dist/three/frame/phase.d.ts +44 -0
  132. package/dist/three/frame/phase.js +80 -0
  133. package/dist/three/frame/phase.js.map +1 -0
  134. package/dist/three/frame/renderer.d.ts +493 -0
  135. package/dist/three/frame/renderer.js +1498 -0
  136. package/dist/three/frame/renderer.js.map +1 -0
  137. package/dist/three/frame/shadow-density-material.d.ts +30 -0
  138. package/dist/three/frame/shadow-density-material.js +123 -0
  139. package/dist/three/frame/shadow-density-material.js.map +1 -0
  140. package/dist/three/frame/spectrum.d.ts +18 -0
  141. package/dist/three/frame/spectrum.js +36 -0
  142. package/dist/three/frame/spectrum.js.map +1 -0
  143. package/dist/three/frame/temporal-material.d.ts +29 -0
  144. package/dist/three/frame/temporal-material.js +152 -0
  145. package/dist/three/frame/temporal-material.js.map +1 -0
  146. package/dist/three/frame/three-internals.d.ts +65 -0
  147. package/dist/three/frame/three-internals.js +150 -0
  148. package/dist/three/frame/three-internals.js.map +1 -0
  149. package/dist/three/frame/transmittance-material.d.ts +31 -0
  150. package/dist/three/frame/transmittance-material.js +315 -0
  151. package/dist/three/frame/transmittance-material.js.map +1 -0
  152. package/dist/three/frame/view.d.ts +103 -0
  153. package/dist/three/frame/view.js +296 -0
  154. package/dist/three/frame/view.js.map +1 -0
  155. package/dist/three/frame/volume-shadow-material.d.ts +36 -0
  156. package/dist/three/frame/volume-shadow-material.js +128 -0
  157. package/dist/three/frame/volume-shadow-material.js.map +1 -0
  158. package/dist/three/frame/volume-shadows.d.ts +153 -0
  159. package/dist/three/frame/volume-shadows.js +756 -0
  160. package/dist/three/frame/volume-shadows.js.map +1 -0
  161. package/dist/three/frame/volume.d.ts +172 -0
  162. package/dist/three/frame/volume.js +256 -0
  163. package/dist/three/frame/volume.js.map +1 -0
  164. package/dist/three/grid-node.d.ts +196 -0
  165. package/dist/three/grid-node.js +510 -0
  166. package/dist/three/grid-node.js.map +1 -0
  167. package/dist/three/index.d.ts +43 -0
  168. package/dist/three/index.js +49 -0
  169. package/dist/three/index.js.map +1 -0
  170. package/dist/three/internal.d.ts +14 -0
  171. package/dist/three/internal.js +14 -0
  172. package/dist/three/internal.js.map +1 -0
  173. package/dist/three/level-set-material.d.ts +112 -0
  174. package/dist/three/level-set-material.js +204 -0
  175. package/dist/three/level-set-material.js.map +1 -0
  176. package/dist/three/material.d.ts +194 -0
  177. package/dist/three/material.js +359 -0
  178. package/dist/three/material.js.map +1 -0
  179. package/dist/three/points.d.ts +84 -0
  180. package/dist/three/points.js +130 -0
  181. package/dist/three/points.js.map +1 -0
  182. package/dist/three/sequence.d.ts +317 -0
  183. package/dist/three/sequence.js +526 -0
  184. package/dist/three/sequence.js.map +1 -0
  185. package/dist/three/sparse-source.d.ts +233 -0
  186. package/dist/three/sparse-source.js +876 -0
  187. package/dist/three/sparse-source.js.map +1 -0
  188. package/dist/three/volume-source.d.ts +167 -0
  189. package/dist/three/volume-source.js +353 -0
  190. package/dist/three/volume-source.js.map +1 -0
  191. package/dist/tools/cpu/compute.d.ts +97 -0
  192. package/dist/tools/cpu/compute.js +218 -0
  193. package/dist/tools/cpu/compute.js.map +1 -0
  194. package/dist/tools/cpu/level-set.d.ts +72 -0
  195. package/dist/tools/cpu/level-set.js +261 -0
  196. package/dist/tools/cpu/level-set.js.map +1 -0
  197. package/dist/tools/cpu/march.d.ts +206 -0
  198. package/dist/tools/cpu/march.js +575 -0
  199. package/dist/tools/cpu/march.js.map +1 -0
  200. package/dist/tools/cpu/probe-coords.d.ts +70 -0
  201. package/dist/tools/cpu/probe-coords.js +116 -0
  202. package/dist/tools/cpu/probe-coords.js.map +1 -0
  203. package/dist/tools/cpu/read-value.d.ts +31 -0
  204. package/dist/tools/cpu/read-value.js +336 -0
  205. package/dist/tools/cpu/read-value.js.map +1 -0
  206. package/dist/tools/cpu/sample-trilinear.d.ts +30 -0
  207. package/dist/tools/cpu/sample-trilinear.js +156 -0
  208. package/dist/tools/cpu/sample-trilinear.js.map +1 -0
  209. package/dist/tools/cpu/stride-tables.d.ts +56 -0
  210. package/dist/tools/cpu/stride-tables.generated.d.ts +1058 -0
  211. package/dist/tools/cpu/stride-tables.generated.js +1266 -0
  212. package/dist/tools/cpu/stride-tables.generated.js.map +1 -0
  213. package/dist/tools/cpu/stride-tables.js +78 -0
  214. package/dist/tools/cpu/stride-tables.js.map +1 -0
  215. package/dist/tools/errors.d.ts +57 -0
  216. package/dist/tools/errors.js +58 -0
  217. package/dist/tools/errors.js.map +1 -0
  218. package/dist/tools/frame/blackbody.d.ts +42 -0
  219. package/dist/tools/frame/blackbody.js +116 -0
  220. package/dist/tools/frame/blackbody.js.map +1 -0
  221. package/dist/tools/frame/emission.d.ts +128 -0
  222. package/dist/tools/frame/emission.js +282 -0
  223. package/dist/tools/frame/emission.js.map +1 -0
  224. package/dist/tools/frame/environment.d.ts +105 -0
  225. package/dist/tools/frame/environment.js +268 -0
  226. package/dist/tools/frame/environment.js.map +1 -0
  227. package/dist/tools/frame/grid.d.ts +302 -0
  228. package/dist/tools/frame/grid.js +703 -0
  229. package/dist/tools/frame/grid.js.map +1 -0
  230. package/dist/tools/frame/index.d.ts +136 -0
  231. package/dist/tools/frame/index.js +348 -0
  232. package/dist/tools/frame/index.js.map +1 -0
  233. package/dist/tools/frame/medium.d.ts +61 -0
  234. package/dist/tools/frame/medium.js +99 -0
  235. package/dist/tools/frame/medium.js.map +1 -0
  236. package/dist/tools/frame/mie-table.d.ts +6 -0
  237. package/dist/tools/frame/mie-table.js +16 -0
  238. package/dist/tools/frame/mie-table.js.map +1 -0
  239. package/dist/tools/frame/mie.d.ts +54 -0
  240. package/dist/tools/frame/mie.js +176 -0
  241. package/dist/tools/frame/mie.js.map +1 -0
  242. package/dist/tools/frame/neural-weights.d.ts +9 -0
  243. package/dist/tools/frame/neural-weights.js +245 -0
  244. package/dist/tools/frame/neural-weights.js.map +1 -0
  245. package/dist/tools/frame/neural.d.ts +80 -0
  246. package/dist/tools/frame/neural.js +150 -0
  247. package/dist/tools/frame/neural.js.map +1 -0
  248. package/dist/tools/frame/pyramid-layout.d.ts +38 -0
  249. package/dist/tools/frame/pyramid-layout.js +53 -0
  250. package/dist/tools/frame/pyramid-layout.js.map +1 -0
  251. package/dist/tools/frame/shadows.d.ts +80 -0
  252. package/dist/tools/frame/shadows.js +182 -0
  253. package/dist/tools/frame/shadows.js.map +1 -0
  254. package/dist/tools/frame/sparse.d.ts +65 -0
  255. package/dist/tools/frame/sparse.js +191 -0
  256. package/dist/tools/frame/sparse.js.map +1 -0
  257. package/dist/tools/frame/spectral.d.ts +203 -0
  258. package/dist/tools/frame/spectral.js +550 -0
  259. package/dist/tools/frame/spectral.js.map +1 -0
  260. package/dist/tools/index.d.ts +106 -0
  261. package/dist/tools/index.js +88 -0
  262. package/dist/tools/index.js.map +1 -0
  263. package/dist/tools/internal.d.ts +46 -0
  264. package/dist/tools/internal.js +31 -0
  265. package/dist/tools/internal.js.map +1 -0
  266. package/dist/tools/nanovdb/build-from-vdb.d.ts +50 -0
  267. package/dist/tools/nanovdb/build-from-vdb.js +92 -0
  268. package/dist/tools/nanovdb/build-from-vdb.js.map +1 -0
  269. package/dist/tools/nanovdb/bytes.d.ts +220 -0
  270. package/dist/tools/nanovdb/bytes.js +345 -0
  271. package/dist/tools/nanovdb/bytes.js.map +1 -0
  272. package/dist/tools/nanovdb/coarse-first.d.ts +62 -0
  273. package/dist/tools/nanovdb/coarse-first.js +86 -0
  274. package/dist/tools/nanovdb/coarse-first.js.map +1 -0
  275. package/dist/tools/nanovdb/index.d.ts +32 -0
  276. package/dist/tools/nanovdb/index.js +24 -0
  277. package/dist/tools/nanovdb/index.js.map +1 -0
  278. package/dist/tools/nanovdb/inspect.d.ts +24 -0
  279. package/dist/tools/nanovdb/inspect.js +63 -0
  280. package/dist/tools/nanovdb/inspect.js.map +1 -0
  281. package/dist/tools/nanovdb/leaf-codec.d.ts +85 -0
  282. package/dist/tools/nanovdb/leaf-codec.js +320 -0
  283. package/dist/tools/nanovdb/leaf-codec.js.map +1 -0
  284. package/dist/tools/nanovdb/quantize.d.ts +43 -0
  285. package/dist/tools/nanovdb/quantize.js +277 -0
  286. package/dist/tools/nanovdb/quantize.js.map +1 -0
  287. package/dist/tools/nanovdb/resample.d.ts +160 -0
  288. package/dist/tools/nanovdb/resample.js +679 -0
  289. package/dist/tools/nanovdb/resample.js.map +1 -0
  290. package/dist/tools/nanovdb/serialize.d.ts +145 -0
  291. package/dist/tools/nanovdb/serialize.js +395 -0
  292. package/dist/tools/nanovdb/serialize.js.map +1 -0
  293. package/dist/tools/nanovdb/stats.d.ts +58 -0
  294. package/dist/tools/nanovdb/stats.js +149 -0
  295. package/dist/tools/nanovdb/stats.js.map +1 -0
  296. package/dist/tools/nanovdb/transform.d.ts +26 -0
  297. package/dist/tools/nanovdb/transform.js +91 -0
  298. package/dist/tools/nanovdb/transform.js.map +1 -0
  299. package/dist/tools/nanovdb/tree.d.ts +175 -0
  300. package/dist/tools/nanovdb/tree.js +518 -0
  301. package/dist/tools/nanovdb/tree.js.map +1 -0
  302. package/dist/tools/nanovdb/write-nvdb.d.ts +39 -0
  303. package/dist/tools/nanovdb/write-nvdb.js +210 -0
  304. package/dist/tools/nanovdb/write-nvdb.js.map +1 -0
  305. package/dist/tools/nvdb-file.d.ts +195 -0
  306. package/dist/tools/nvdb-file.js +606 -0
  307. package/dist/tools/nvdb-file.js.map +1 -0
  308. package/dist/tools/nvdb-stream.d.ts +138 -0
  309. package/dist/tools/nvdb-stream.js +365 -0
  310. package/dist/tools/nvdb-stream.js.map +1 -0
  311. package/dist/tools/vdb/bit-utils.d.ts +20 -0
  312. package/dist/tools/vdb/bit-utils.js +42 -0
  313. package/dist/tools/vdb/bit-utils.js.map +1 -0
  314. package/dist/tools/vdb/blosc.d.ts +56 -0
  315. package/dist/tools/vdb/blosc.js +231 -0
  316. package/dist/tools/vdb/blosc.js.map +1 -0
  317. package/dist/tools/vdb/byte-reader.d.ts +40 -0
  318. package/dist/tools/vdb/byte-reader.js +139 -0
  319. package/dist/tools/vdb/byte-reader.js.map +1 -0
  320. package/dist/tools/vdb/compression.d.ts +73 -0
  321. package/dist/tools/vdb/compression.js +249 -0
  322. package/dist/tools/vdb/compression.js.map +1 -0
  323. package/dist/tools/vdb/errors.d.ts +10 -0
  324. package/dist/tools/vdb/errors.js +11 -0
  325. package/dist/tools/vdb/errors.js.map +1 -0
  326. package/dist/tools/vdb/grid.d.ts +37 -0
  327. package/dist/tools/vdb/grid.js +147 -0
  328. package/dist/tools/vdb/grid.js.map +1 -0
  329. package/dist/tools/vdb/half-float.d.ts +9 -0
  330. package/dist/tools/vdb/half-float.js +24 -0
  331. package/dist/tools/vdb/half-float.js.map +1 -0
  332. package/dist/tools/vdb/index.d.ts +3 -0
  333. package/dist/tools/vdb/index.js +3 -0
  334. package/dist/tools/vdb/index.js.map +1 -0
  335. package/dist/tools/vdb/inflate.d.ts +24 -0
  336. package/dist/tools/vdb/inflate.js +334 -0
  337. package/dist/tools/vdb/inflate.js.map +1 -0
  338. package/dist/tools/vdb/metadata.d.ts +17 -0
  339. package/dist/tools/vdb/metadata.js +72 -0
  340. package/dist/tools/vdb/metadata.js.map +1 -0
  341. package/dist/tools/vdb/parse.d.ts +25 -0
  342. package/dist/tools/vdb/parse.js +171 -0
  343. package/dist/tools/vdb/parse.js.map +1 -0
  344. package/dist/tools/vdb/point-render-data.d.ts +31 -0
  345. package/dist/tools/vdb/point-render-data.js +57 -0
  346. package/dist/tools/vdb/point-render-data.js.map +1 -0
  347. package/dist/tools/vdb/points.d.ts +160 -0
  348. package/dist/tools/vdb/points.js +794 -0
  349. package/dist/tools/vdb/points.js.map +1 -0
  350. package/dist/tools/vdb/transform.d.ts +23 -0
  351. package/dist/tools/vdb/transform.js +54 -0
  352. package/dist/tools/vdb/transform.js.map +1 -0
  353. package/dist/tools/vdb/tree.d.ts +111 -0
  354. package/dist/tools/vdb/tree.js +228 -0
  355. package/dist/tools/vdb/tree.js.map +1 -0
  356. package/dist/tools/vdb/types.d.ts +138 -0
  357. package/dist/tools/vdb/types.js +3 -0
  358. package/dist/tools/vdb/types.js.map +1 -0
  359. package/dist/tools/wvdb/bake.d.ts +116 -0
  360. package/dist/tools/wvdb/bake.js +311 -0
  361. package/dist/tools/wvdb/bake.js.map +1 -0
  362. package/dist/tools/wvdb/dense.d.ts +112 -0
  363. package/dist/tools/wvdb/dense.js +309 -0
  364. package/dist/tools/wvdb/dense.js.map +1 -0
  365. package/dist/tools/wvdb/format.d.ts +161 -0
  366. package/dist/tools/wvdb/format.js +303 -0
  367. package/dist/tools/wvdb/format.js.map +1 -0
  368. package/dist/tools/wvdb/index.d.ts +13 -0
  369. package/dist/tools/wvdb/index.js +14 -0
  370. package/dist/tools/wvdb/index.js.map +1 -0
  371. package/dist/tools/wvdb/level-set.d.ts +48 -0
  372. package/dist/tools/wvdb/level-set.js +153 -0
  373. package/dist/tools/wvdb/level-set.js.map +1 -0
  374. package/dist/tools/wvdb/nanovdb.d.ts +54 -0
  375. package/dist/tools/wvdb/nanovdb.js +60 -0
  376. package/dist/tools/wvdb/nanovdb.js.map +1 -0
  377. package/dist/tools/wvdb/read.d.ts +260 -0
  378. package/dist/tools/wvdb/read.js +743 -0
  379. package/dist/tools/wvdb/read.js.map +1 -0
  380. package/dist/tools/wvdb/sha256.d.ts +7 -0
  381. package/dist/tools/wvdb/sha256.js +76 -0
  382. package/dist/tools/wvdb/sha256.js.map +1 -0
  383. package/dist/tools/wvdb/write.d.ts +127 -0
  384. package/dist/tools/wvdb/write.js +396 -0
  385. package/dist/tools/wvdb/write.js.map +1 -0
  386. package/package.json +82 -4
  387. package/vendor/LICENSE +201 -0
  388. package/vendor/NOTICE +19 -0
  389. package/vendor/VENDOR.md +85 -0
  390. package/vendor/pnanovdb.wgsl +1539 -0
@@ -0,0 +1,43 @@
1
+ /**
2
+ * @pmndrs/vdb/three — the three.js adapter over the engine-free core (D8).
3
+ *
4
+ * `getDevice` / `getGPUTexture` reach the renderer's WebGPU handles, so the
5
+ * pool and the other pmndrs tools share one device. `VDBGridNode` puts a
6
+ * `VDBGridPool` into three's node system (`vdbSample`, `vdbReadValue`, or the
7
+ * module as a `wgslFn` include). `VDBVolumeMaterial` raymarches one pooled
8
+ * grid; `VDBSequence` plays a frame sequence into one pool id with
9
+ * `pool.replace`. `vdbGridStats` / `vdbDecodeToAtlas` run the core compute
10
+ * tools through the renderer's device. `VDBFrameVolume` / `VDBFrameRenderer`
11
+ * are mjurczyk's froxel renderer on a dense or sparse volume source.
12
+ *
13
+ * There is no renderer bootstrap: create the device yourself
14
+ * (`adapter.requestDevice({ requiredLimits: VDBGridPool.requiredLimits(adapter) })`)
15
+ * and pass it, `new WebGPURenderer({ device })`, so the pool outlives
16
+ * `renderer.dispose()`.
17
+ *
18
+ * This barrel is the public API (D32). The frame renderer's pass materials, shader chunks and three
19
+ * internals hooks live in `./internal.ts`, imported by path by tests and harnesses; it is not a package
20
+ * export.
21
+ */
22
+ export { getDevice, getGPUTexture } from "./device.js";
23
+ export type { VDBThreeBackendLike, VDBThreeRendererLike } from "./device.js";
24
+ export { VDBGridNode, vdbReadValue, vdbSample } from "./grid-node.js";
25
+ export type { VDBGridNodeOptions, VDBGridNodePoolLike, VDBSampleOptions, VDBTslNode } from "./grid-node.js";
26
+ export { VDBVolumeMaterial, vdbProxyGeometry, VDB_VOLUME_MAX_STEPS_CAP, VDB_VOLUME_SHADOW_STEPS_CAP, VDB_VOLUME_SAMPLE_BUDGET_CAP, } from "./material.js";
27
+ export type { VDBVolumeMaterialParameters, VDBProxyGridInfo, VDBUintUniform } from "./material.js";
28
+ export { VDBSequence } from "./sequence.js";
29
+ export type { VDBSequenceLoopMode, VDBSequenceOptions, VDBSequenceRange, VDBSequenceStats, VDBSequenceTarget, VDBSequencePoolLike, VDBFrameLoader, } from "./sequence.js";
30
+ export { VDBLevelSetMaterial, VDB_LEVEL_SET_SAMPLES_CAP } from "./level-set-material.js";
31
+ export type { VDBLevelSetMaterialParameters } from "./level-set-material.js";
32
+ export { VDBPoints } from "./points.js";
33
+ export type { VDBPointsData, VDBPointsOptions } from "./points.js";
34
+ export { vdbGridStats, vdbDecodeToAtlas } from "./compute.js";
35
+ export type { VDBThreeGridStatsOptions, VDBGridStatsResult, VDBThreeDecodeToAtlasOptions, VDBDecodeToAtlasResult } from "./compute.js";
36
+ export { vdbDenseTextures, vdbVolumeUniforms, vdbVolumeNodes } from "./volume-source.js";
37
+ export type { VDBDenseChannelTextures, VDBThreeDenseSource, VDBVolumeNodes, VDBVolumeNodesOptions, VDBVolumeUniformParameters, VDBVolumeUniforms, VDBThreeVolumeSource, VDBThreeSourceFactory, } from "./volume-source.js";
38
+ export { vdbSparseSource } from "./sparse-source.js";
39
+ export type { VDBSparseLod, VDBSparseSourceGrids, VDBSparseSourceOptions, VDBThreeSparseSource, VDBSparseVolumeUniforms, VDBSparsePyramid, VDBIndexBox, } from "./sparse-source.js";
40
+ export { vdbCoarseFirstApply, vdbStreamCoarseFirst } from "./coarse-first.js";
41
+ export type { VDBCoarseFirstBind, VDBCoarseFirstBindPoolLike, VDBCoarseFirstEvent, VDBCoarseFirstOptions, VDBCoarseFirstPoolLike, VDBCoarseFirstResult, VDBCoarseFirstSource, } from "./coarse-first.js";
42
+ export { VDBFrameVolume, VDBFrameRenderer, vdbFrameRenderer, vdbFrameLights, vdbFrameAllLights, getFrameMediumProps as vdbFrameMedium, VDBFrameEmissionLight, vdbFrameBlackbodyEmission, } from "./frame/index.js";
43
+ export type { VDBFrameVolumeProps, VDBFrameRendererSettings, VDBFramePassHook, VDBFramePass, VDBFrameRedrawStats, VDBFramePhase, VDBFrameMultipleScattering, VDBFrameMediumVolumeProps, VDBFrameEmissionLightProps, VDBFrameBlackbodyHook, } from "./frame/index.js";
@@ -0,0 +1,49 @@
1
+ /**
2
+ * @pmndrs/vdb/three — the three.js adapter over the engine-free core (D8).
3
+ *
4
+ * `getDevice` / `getGPUTexture` reach the renderer's WebGPU handles, so the
5
+ * pool and the other pmndrs tools share one device. `VDBGridNode` puts a
6
+ * `VDBGridPool` into three's node system (`vdbSample`, `vdbReadValue`, or the
7
+ * module as a `wgslFn` include). `VDBVolumeMaterial` raymarches one pooled
8
+ * grid; `VDBSequence` plays a frame sequence into one pool id with
9
+ * `pool.replace`. `vdbGridStats` / `vdbDecodeToAtlas` run the core compute
10
+ * tools through the renderer's device. `VDBFrameVolume` / `VDBFrameRenderer`
11
+ * are mjurczyk's froxel renderer on a dense or sparse volume source.
12
+ *
13
+ * There is no renderer bootstrap: create the device yourself
14
+ * (`adapter.requestDevice({ requiredLimits: VDBGridPool.requiredLimits(adapter) })`)
15
+ * and pass it, `new WebGPURenderer({ device })`, so the pool outlives
16
+ * `renderer.dispose()`.
17
+ *
18
+ * This barrel is the public API (D32). The frame renderer's pass materials, shader chunks and three
19
+ * internals hooks live in `./internal.ts`, imported by path by tests and harnesses; it is not a package
20
+ * export.
21
+ */
22
+ // K2.1/K2.2: the adapter over the engine-free core (docs/dev/design/K1-core.md §6). `getDevice` and
23
+ // `getGPUTexture` keep the helper names the other pmndrs tools use (D32).
24
+ export { getDevice, getGPUTexture } from "./device.js";
25
+ export { VDBGridNode, vdbReadValue, vdbSample } from "./grid-node.js";
26
+ // K2.3: the volume material and the sequence player on the pool.
27
+ export { VDBVolumeMaterial, vdbProxyGeometry, VDB_VOLUME_MAX_STEPS_CAP, VDB_VOLUME_SHADOW_STEPS_CAP, VDB_VOLUME_SAMPLE_BUDGET_CAP, } from "./material.js";
28
+ export { VDBSequence } from "./sequence.js";
29
+ // K3.7 (R1 §6 Step 7): level-set surfaces traced on the sparse pool, and point grids as sprites.
30
+ export { VDBLevelSetMaterial, VDB_LEVEL_SET_SAMPLES_CAP } from "./level-set-material.js";
31
+ export { VDBPoints } from "./points.js";
32
+ // K2.3: compute wrappers over the core tools (renderer in, promise out). The
33
+ // core's `vdbGridStatsGpu` / `vdbDecodeToAtlasGpu` take a device and an encoder;
34
+ // the value transform is the core's `vdbApplyValueTransform` (CPU).
35
+ export { vdbGridStats, vdbDecodeToAtlas } from "./compute.js";
36
+ // K3.0: the dense `.wvdb` volume source (R1 §4.2) in his createVolumeNodes() shape.
37
+ export { vdbDenseTextures, vdbVolumeUniforms, vdbVolumeNodes } from "./volume-source.js";
38
+ // K3.2: the sparse volume source (a VDBGridPool grid behind the same seam) with its LOD strategies.
39
+ export { vdbSparseSource } from "./sparse-source.js";
40
+ // K4.16: coarse-first `.nvdb` streaming into one pool id (add the preview with
41
+ // the full size reserved, then replace). Engine-free glue; here because tools
42
+ // may not import the core.
43
+ export { vdbCoarseFirstApply, vdbStreamCoarseFirst } from "./coarse-first.js";
44
+ // K3.1–K3.6: the froxel renderer (his FrameVolume / FrameRenderer) on a volume source: the volume, the
45
+ // renderer, the light-mask flags, the measured media, the emission light and its blackbody colour hook.
46
+ export { VDBFrameVolume, VDBFrameRenderer, vdbFrameRenderer, vdbFrameLights, vdbFrameAllLights,
47
+ // His helper name stays inside frame/ (diffable with upstream); the public name follows D17.
48
+ getFrameMediumProps as vdbFrameMedium, VDBFrameEmissionLight, vdbFrameBlackbodyEmission, } from "./frame/index.js";
49
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/three/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,oGAAoG;AACpG,0EAA0E;AAC1E,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEvD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAGtE,iEAAiE;AACjE,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,wBAAwB,EACxB,2BAA2B,EAC3B,4BAA4B,GAC7B,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAW5C,iGAAiG;AACjG,OAAO,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAEzF,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,6EAA6E;AAC7E,iFAAiF;AACjF,oEAAoE;AACpE,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAG9D,oFAAoF;AACpF,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAYzF,oGAAoG;AACpG,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAWrD,+EAA+E;AAC/E,8EAA8E;AAC9E,2BAA2B;AAC3B,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAW9E,uGAAuG;AACvG,wGAAwG;AACxG,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,iBAAiB;AACjB,6FAA6F;AAC7F,mBAAmB,IAAI,cAAc,EACrC,qBAAqB,EACrB,yBAAyB,GAC1B,MAAM,kBAAkB,CAAC","sourcesContent":["/**\n * @pmndrs/vdb/three — the three.js adapter over the engine-free core (D8).\n *\n * `getDevice` / `getGPUTexture` reach the renderer's WebGPU handles, so the\n * pool and the other pmndrs tools share one device. `VDBGridNode` puts a\n * `VDBGridPool` into three's node system (`vdbSample`, `vdbReadValue`, or the\n * module as a `wgslFn` include). `VDBVolumeMaterial` raymarches one pooled\n * grid; `VDBSequence` plays a frame sequence into one pool id with\n * `pool.replace`. `vdbGridStats` / `vdbDecodeToAtlas` run the core compute\n * tools through the renderer's device. `VDBFrameVolume` / `VDBFrameRenderer`\n * are mjurczyk's froxel renderer on a dense or sparse volume source.\n *\n * There is no renderer bootstrap: create the device yourself\n * (`adapter.requestDevice({ requiredLimits: VDBGridPool.requiredLimits(adapter) })`)\n * and pass it, `new WebGPURenderer({ device })`, so the pool outlives\n * `renderer.dispose()`.\n *\n * This barrel is the public API (D32). The frame renderer's pass materials, shader chunks and three\n * internals hooks live in `./internal.ts`, imported by path by tests and harnesses; it is not a package\n * export.\n */\n\n// K2.1/K2.2: the adapter over the engine-free core (docs/dev/design/K1-core.md §6). `getDevice` and\n// `getGPUTexture` keep the helper names the other pmndrs tools use (D32).\nexport { getDevice, getGPUTexture } from \"./device.js\";\nexport type { VDBThreeBackendLike, VDBThreeRendererLike } from \"./device.js\";\nexport { VDBGridNode, vdbReadValue, vdbSample } from \"./grid-node.js\";\nexport type { VDBGridNodeOptions, VDBGridNodePoolLike, VDBSampleOptions, VDBTslNode } from \"./grid-node.js\";\n\n// K2.3: the volume material and the sequence player on the pool.\nexport {\n VDBVolumeMaterial,\n vdbProxyGeometry,\n VDB_VOLUME_MAX_STEPS_CAP,\n VDB_VOLUME_SHADOW_STEPS_CAP,\n VDB_VOLUME_SAMPLE_BUDGET_CAP,\n} from \"./material.js\";\nexport type { VDBVolumeMaterialParameters, VDBProxyGridInfo, VDBUintUniform } from \"./material.js\";\nexport { VDBSequence } from \"./sequence.js\";\nexport type {\n VDBSequenceLoopMode,\n VDBSequenceOptions,\n VDBSequenceRange,\n VDBSequenceStats,\n VDBSequenceTarget,\n VDBSequencePoolLike,\n VDBFrameLoader,\n} from \"./sequence.js\";\n\n// K3.7 (R1 §6 Step 7): level-set surfaces traced on the sparse pool, and point grids as sprites.\nexport { VDBLevelSetMaterial, VDB_LEVEL_SET_SAMPLES_CAP } from \"./level-set-material.js\";\nexport type { VDBLevelSetMaterialParameters } from \"./level-set-material.js\";\nexport { VDBPoints } from \"./points.js\";\nexport type { VDBPointsData, VDBPointsOptions } from \"./points.js\";\n\n// K2.3: compute wrappers over the core tools (renderer in, promise out). The\n// core's `vdbGridStatsGpu` / `vdbDecodeToAtlasGpu` take a device and an encoder;\n// the value transform is the core's `vdbApplyValueTransform` (CPU).\nexport { vdbGridStats, vdbDecodeToAtlas } from \"./compute.js\";\nexport type { VDBThreeGridStatsOptions, VDBGridStatsResult, VDBThreeDecodeToAtlasOptions, VDBDecodeToAtlasResult } from \"./compute.js\";\n\n// K3.0: the dense `.wvdb` volume source (R1 §4.2) in his createVolumeNodes() shape.\nexport { vdbDenseTextures, vdbVolumeUniforms, vdbVolumeNodes } from \"./volume-source.js\";\nexport type {\n VDBDenseChannelTextures,\n VDBThreeDenseSource,\n VDBVolumeNodes,\n VDBVolumeNodesOptions,\n VDBVolumeUniformParameters,\n VDBVolumeUniforms,\n VDBThreeVolumeSource,\n VDBThreeSourceFactory,\n} from \"./volume-source.js\";\n\n// K3.2: the sparse volume source (a VDBGridPool grid behind the same seam) with its LOD strategies.\nexport { vdbSparseSource } from \"./sparse-source.js\";\nexport type {\n VDBSparseLod,\n VDBSparseSourceGrids,\n VDBSparseSourceOptions,\n VDBThreeSparseSource,\n VDBSparseVolumeUniforms,\n VDBSparsePyramid,\n VDBIndexBox,\n} from \"./sparse-source.js\";\n\n// K4.16: coarse-first `.nvdb` streaming into one pool id (add the preview with\n// the full size reserved, then replace). Engine-free glue; here because tools\n// may not import the core.\nexport { vdbCoarseFirstApply, vdbStreamCoarseFirst } from \"./coarse-first.js\";\nexport type {\n VDBCoarseFirstBind,\n VDBCoarseFirstBindPoolLike,\n VDBCoarseFirstEvent,\n VDBCoarseFirstOptions,\n VDBCoarseFirstPoolLike,\n VDBCoarseFirstResult,\n VDBCoarseFirstSource,\n} from \"./coarse-first.js\";\n\n// K3.1–K3.6: the froxel renderer (his FrameVolume / FrameRenderer) on a volume source: the volume, the\n// renderer, the light-mask flags, the measured media, the emission light and its blackbody colour hook.\nexport {\n VDBFrameVolume,\n VDBFrameRenderer,\n vdbFrameRenderer,\n vdbFrameLights,\n vdbFrameAllLights,\n // His helper name stays inside frame/ (diffable with upstream); the public name follows D17.\n getFrameMediumProps as vdbFrameMedium,\n VDBFrameEmissionLight,\n vdbFrameBlackbodyEmission,\n} from \"./frame/index.js\";\nexport type {\n VDBFrameVolumeProps,\n VDBFrameRendererSettings,\n VDBFramePassHook,\n VDBFramePass,\n VDBFrameRedrawStats,\n VDBFramePhase,\n VDBFrameMultipleScattering,\n VDBFrameMediumVolumeProps,\n VDBFrameEmissionLightProps,\n VDBFrameBlackbodyHook,\n} from \"./frame/index.js\";\n"]}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @pmndrs/vdb/three internals (D32): NOT a package export.
3
+ *
4
+ * Everything public (`./index.ts`) plus what tests and harnesses need that a user doesn't: the frame
5
+ * renderer's pass materials (inject, integrate, 'frame' lighting, shadows, emission), its TSL shader
6
+ * chunks, the uniform packers and froxel layout helpers behind the settings, the volume shadow system
7
+ * and the three-internals hooks. Import it by path (`src/three/internal.ts`); its names can change
8
+ * without notice.
9
+ */
10
+ export * from "./index.js";
11
+ export { vdbAttenuatedPointSize, vdbPointDiscTexture } from "./points.js";
12
+ export { vdbMinComponent, vdbMaxComponent } from "./volume-source.js";
13
+ export { VDBFrameInjectMaterial, VDBFrameIntegrateMaterial, VDBFrameShadowDensityMaterial, VDBFrameTransmittanceMaterial, VDBFrameDensityMaterial, VDBFrameLightingMaterial, VDBFrameTemporalMaterial, VDBFrameEnvironmentMapMaterial, VDBFrameEnvironmentGridMaterial, VDBFrameGridMipMaterial, vdbFrameChunks, getFramePhase as vdbFramePhase, getFramePhaseSpectrum as vdbFramePhaseSpectrum, getFramePhaseAsymmetry as vdbFramePhaseAsymmetry, getFrameMultipleScattering as vdbFrameMultipleScattering, getFrameScatteringOctaves as vdbFrameScatteringOctavesInto, getFrameTwoSidedDiffusion as vdbFrameTwoSidedMode, getAtlasLayout as vdbFrameAtlasLayout, getFroxelSize as vdbFroxelSize, getFroxelSlice as vdbFroxelSlice, getFroxelSliceRange as vdbFroxelSliceRange, getFroxelRect as vdbFroxelRect, getFroxelArea as vdbFroxelArea, getFrameExtinctionSpectrum as vdbFrameExtinctionSpectrumInto, getFrameAngstromExponent as vdbFrameAngstromExponent, frameAngstromExponents as vdbFrameAngstromExponents, VDBFrameVolumeShadows, VDBFrameVolumeShadowMaterial, VDBFrameEmissionLightNode, VDBFrameEmissionDirectionMaterial, VDBFrameEmissionReduceMaterial, VDBFrameEmissionProbeMaterial, vdbFrameCheckLightReset, } from "./frame/index.js";
14
+ export type { VDBFrameInjectMaterialOptions, FrameVolumeRecord, FroxelArea, VDBFrameShadowEntry, } from "./frame/index.js";
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @pmndrs/vdb/three internals (D32): NOT a package export.
3
+ *
4
+ * Everything public (`./index.ts`) plus what tests and harnesses need that a user doesn't: the frame
5
+ * renderer's pass materials (inject, integrate, 'frame' lighting, shadows, emission), its TSL shader
6
+ * chunks, the uniform packers and froxel layout helpers behind the settings, the volume shadow system
7
+ * and the three-internals hooks. Import it by path (`src/three/internal.ts`); its names can change
8
+ * without notice.
9
+ */
10
+ export * from "./index.js";
11
+ export { vdbAttenuatedPointSize, vdbPointDiscTexture } from "./points.js";
12
+ export { vdbMinComponent, vdbMaxComponent } from "./volume-source.js";
13
+ export { VDBFrameInjectMaterial, VDBFrameIntegrateMaterial, VDBFrameShadowDensityMaterial, VDBFrameTransmittanceMaterial, VDBFrameDensityMaterial, VDBFrameLightingMaterial, VDBFrameTemporalMaterial, VDBFrameEnvironmentMapMaterial, VDBFrameEnvironmentGridMaterial, VDBFrameGridMipMaterial, vdbFrameChunks, getFramePhase as vdbFramePhase, getFramePhaseSpectrum as vdbFramePhaseSpectrum, getFramePhaseAsymmetry as vdbFramePhaseAsymmetry, getFrameMultipleScattering as vdbFrameMultipleScattering, getFrameScatteringOctaves as vdbFrameScatteringOctavesInto, getFrameTwoSidedDiffusion as vdbFrameTwoSidedMode, getAtlasLayout as vdbFrameAtlasLayout, getFroxelSize as vdbFroxelSize, getFroxelSlice as vdbFroxelSlice, getFroxelSliceRange as vdbFroxelSliceRange, getFroxelRect as vdbFroxelRect, getFroxelArea as vdbFroxelArea, getFrameExtinctionSpectrum as vdbFrameExtinctionSpectrumInto, getFrameAngstromExponent as vdbFrameAngstromExponent, frameAngstromExponents as vdbFrameAngstromExponents, VDBFrameVolumeShadows, VDBFrameVolumeShadowMaterial, VDBFrameEmissionLightNode, VDBFrameEmissionDirectionMaterial, VDBFrameEmissionReduceMaterial, VDBFrameEmissionProbeMaterial, vdbFrameCheckLightReset, } from "./frame/index.js";
14
+ //# sourceMappingURL=internal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.js","sourceRoot":"","sources":["../../src/three/internal.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,cAAc,YAAY,CAAC;AAE3B,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EACL,sBAAsB,EACtB,yBAAyB,EACzB,6BAA6B,EAC7B,6BAA6B,EAC7B,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,EACxB,8BAA8B,EAC9B,+BAA+B,EAC/B,uBAAuB,EACvB,cAAc,EACd,aAAa,IAAI,aAAa,EAC9B,qBAAqB,IAAI,qBAAqB,EAC9C,sBAAsB,IAAI,sBAAsB,EAChD,0BAA0B,IAAI,0BAA0B,EACxD,yBAAyB,IAAI,6BAA6B,EAC1D,yBAAyB,IAAI,oBAAoB,EACjD,cAAc,IAAI,mBAAmB,EACrC,aAAa,IAAI,aAAa,EAC9B,cAAc,IAAI,cAAc,EAChC,mBAAmB,IAAI,mBAAmB,EAC1C,aAAa,IAAI,aAAa,EAC9B,aAAa,IAAI,aAAa,EAC9B,0BAA0B,IAAI,8BAA8B,EAC5D,wBAAwB,IAAI,wBAAwB,EACpD,sBAAsB,IAAI,yBAAyB,EACnD,qBAAqB,EACrB,4BAA4B,EAC5B,yBAAyB,EACzB,iCAAiC,EACjC,8BAA8B,EAC9B,6BAA6B,EAC7B,uBAAuB,GACxB,MAAM,kBAAkB,CAAC","sourcesContent":["/**\n * @pmndrs/vdb/three internals (D32): NOT a package export.\n *\n * Everything public (`./index.ts`) plus what tests and harnesses need that a user doesn't: the frame\n * renderer's pass materials (inject, integrate, 'frame' lighting, shadows, emission), its TSL shader\n * chunks, the uniform packers and froxel layout helpers behind the settings, the volume shadow system\n * and the three-internals hooks. Import it by path (`src/three/internal.ts`); its names can change\n * without notice.\n */\n\nexport * from \"./index.js\";\n\nexport { vdbAttenuatedPointSize, vdbPointDiscTexture } from \"./points.js\";\nexport { vdbMinComponent, vdbMaxComponent } from \"./volume-source.js\";\nexport {\n VDBFrameInjectMaterial,\n VDBFrameIntegrateMaterial,\n VDBFrameShadowDensityMaterial,\n VDBFrameTransmittanceMaterial,\n VDBFrameDensityMaterial,\n VDBFrameLightingMaterial,\n VDBFrameTemporalMaterial,\n VDBFrameEnvironmentMapMaterial,\n VDBFrameEnvironmentGridMaterial,\n VDBFrameGridMipMaterial,\n vdbFrameChunks,\n getFramePhase as vdbFramePhase,\n getFramePhaseSpectrum as vdbFramePhaseSpectrum,\n getFramePhaseAsymmetry as vdbFramePhaseAsymmetry,\n getFrameMultipleScattering as vdbFrameMultipleScattering,\n getFrameScatteringOctaves as vdbFrameScatteringOctavesInto,\n getFrameTwoSidedDiffusion as vdbFrameTwoSidedMode,\n getAtlasLayout as vdbFrameAtlasLayout,\n getFroxelSize as vdbFroxelSize,\n getFroxelSlice as vdbFroxelSlice,\n getFroxelSliceRange as vdbFroxelSliceRange,\n getFroxelRect as vdbFroxelRect,\n getFroxelArea as vdbFroxelArea,\n getFrameExtinctionSpectrum as vdbFrameExtinctionSpectrumInto,\n getFrameAngstromExponent as vdbFrameAngstromExponent,\n frameAngstromExponents as vdbFrameAngstromExponents,\n VDBFrameVolumeShadows,\n VDBFrameVolumeShadowMaterial,\n VDBFrameEmissionLightNode,\n VDBFrameEmissionDirectionMaterial,\n VDBFrameEmissionReduceMaterial,\n VDBFrameEmissionProbeMaterial,\n vdbFrameCheckLightReset,\n} from \"./frame/index.js\";\nexport type {\n VDBFrameInjectMaterialOptions,\n FrameVolumeRecord,\n FroxelArea,\n VDBFrameShadowEntry,\n} from \"./frame/index.js\";\n"]}
@@ -0,0 +1,112 @@
1
+ /**
2
+ * `VDBLevelSetMaterial`: a NanoVDB level set's zero surface, traced on the GPU
3
+ * on the sparse pool (K3.7, R1 §6 Step 7), as a three r187
4
+ * `MeshStandardNodeMaterial` (lights, shadows, depth, fog: three's own).
5
+ *
6
+ * const grids = new VDBGridNode(renderer, pool, { profile: 'march', helpers: ['levelSet'] });
7
+ * const material = new VDBLevelSetMaterial(renderer, grids, id, { color: 0xffffff, roughness: 0.5 });
8
+ * scene.add(new Mesh(vdbProxyGeometry(pool.info(id), { pad: 1 }), material));
9
+ * // per frame: pool.update(encoder) (or pool.flush()), then grids.update(), then render.
10
+ *
11
+ * Portions derived from mjurczyk/openvdb (MIT), commit 75e7345
12
+ * (`src/three-openvdb/levelset/webgpu/LevelSetSurfaceMaterial.js`,
13
+ * `LevelSetSurfaceCore.js`): the back-face proxy box (the camera can be
14
+ * inside), perspective and orthographic rays (so shadow passes work), the mask,
15
+ * depth, received-shadow position and the `setupLighting` override that moves
16
+ * `positionView` to the hit. Copyright (c) mjurczyk/openvdb contributors, MIT
17
+ * (see THIRD_PARTY_NOTICES.md). Changes: the trace is the core's `vdbLevelSetHit` on
18
+ * the sparse tree (HDDA skip, full-resolution trilinear SDF) instead of a
19
+ * sphere trace of a dense 8-bit texture; the ray comes from the pixel through
20
+ * the inverse projection, not from interpolated box positions; the normal is
21
+ * `vdbLevelSetNormal` (central differences at `normalStep` voxels through the
22
+ * grid affine); the proxy is in world space and the grid is placed with
23
+ * `pool.setTransform` (DIVERGES.md).
24
+ *
25
+ * The trace runs in the grid's index space: `o = worldToIndex(ray origin)`,
26
+ * `d = worldToIndexDir(unit world direction)`, so `t` is in world units. The
27
+ * ray is the pixel's (`viewportUV` through `cameraProjectionMatrixInverse`):
28
+ * perspective from `cameraPosition` over `t >= 0`; orthographic from the pixel
29
+ * on the camera plane along the view axis over `t` in `[-1e5, 1e5]`. The mesh
30
+ * must have an identity transform (the pool record holds the grid's
31
+ * placement); give it `vdbProxyGeometry(pool.info(id), { pad: 1 })`, which
32
+ * covers the trilinear support the trace clips to.
33
+ */
34
+ import * as THREE from "three";
35
+ import { MeshStandardNodeMaterial } from "three/webgpu";
36
+ import * as TSL from "three/tsl";
37
+ import { type VDBThreeRendererLike } from "./device.js";
38
+ import { VDBGridNode, type VDBTslNode } from "./grid-node.js";
39
+ import type { VDBUintUniform } from "./material.js";
40
+ /** Default compiled cap on the samples one fragment's trace takes (the live `maxSamples` clamps under it). */
41
+ export declare const VDB_LEVEL_SET_SAMPLES_CAP = 1024;
42
+ /** Parameters of {@link VDBLevelSetMaterial}: three's standard material parameters plus the trace's. */
43
+ export interface VDBLevelSetMaterialParameters extends THREE.MeshStandardMaterialParameters {
44
+ /**
45
+ * Index voxels per SDF unit. Default: `1 / voxelSize.x` from `grids.pool.info(id)` when the pool
46
+ * has `info` and the id is a number, else 1. A level set stores distances in its own world units,
47
+ * so this is 1 / its NanoVDB voxel size.
48
+ */
49
+ sdfToIndex?: number;
50
+ /** Trilinear samples per fragment trace (live), clamped to `[1, maxSamplesCap]`. Default 512. */
51
+ maxSamples?: number;
52
+ /** Compiled cap on {@link maxSamples}. Default {@link VDB_LEVEL_SET_SAMPLES_CAP}. */
53
+ maxSamplesCap?: number;
54
+ /** Central-difference step of the normal, in index voxels (live). Default 1. */
55
+ normalStep?: number;
56
+ }
57
+ type ScalarUniform = ReturnType<typeof TSL.uniform> & {
58
+ value: number;
59
+ };
60
+ /**
61
+ * A level set's surface on a world-space proxy box (see the file comment).
62
+ * Shades as a `MeshStandardNodeMaterial`: `color`, `roughness`, `metalness`,
63
+ * maps-free; lights and shadows read the hit point.
64
+ *
65
+ * - Exposes the trace as TSL nodes for custom shading or debugging:
66
+ * {@link hitWorldNode}, {@link hitViewNode}, {@link hitMaskNode},
67
+ * {@link normalWorldNode}, {@link normalViewNode} (e.g. `material.colorNode =
68
+ * material.normalViewNode.mul(0.5).add(0.5)` with no lights shows the normals).
69
+ * - Perspective and orthographic cameras (directional-light shadow maps).
70
+ *
71
+ * @typeParam TGridId What the constructor got as the id: a number (default)
72
+ * makes {@link gridId} a `uint` uniform; a node is kept as given.
73
+ */
74
+ export declare class VDBLevelSetMaterial<TGridId extends number | VDBTslNode = number> extends MeshStandardNodeMaterial {
75
+ readonly isVDBLevelSetMaterial = true;
76
+ /** The pool node this material reads. */
77
+ readonly grids: VDBGridNode;
78
+ /** The grid id: a `uint` uniform for a numeric id (`material.gridId.value = otherId`), else the caller's node. */
79
+ readonly gridId: TGridId extends number ? VDBUintUniform : VDBTslNode;
80
+ /** Index voxels per SDF unit (live). */
81
+ readonly sdfToIndex: ScalarUniform;
82
+ /** Trilinear samples per trace (live, clamped to the compiled cap). */
83
+ readonly maxSamples: ScalarUniform;
84
+ /** Central-difference step of the normal in index voxels (live). */
85
+ readonly normalStep: ScalarUniform;
86
+ /** The trace entry's WGSL (for inspection and tests). */
87
+ readonly traceSource: string;
88
+ /** `vec4(hit world position, 1)` on a hit, `vec4(0)` on a miss (fragment stage). */
89
+ readonly traceNode: VDBTslNode;
90
+ /** The hit in world space. */
91
+ readonly hitWorldNode: VDBTslNode;
92
+ /** The hit in view space. */
93
+ readonly hitViewNode: VDBTslNode;
94
+ /** True where the ray hit the surface (the material's `maskNode`). */
95
+ readonly hitMaskNode: VDBTslNode;
96
+ /** World-space unit normal at the hit. */
97
+ readonly normalWorldNode: VDBTslNode;
98
+ /** View-space unit normal at the hit (the material's `normalNode`). */
99
+ readonly normalViewNode: VDBTslNode;
100
+ /**
101
+ * @param renderer The initialized `WebGPURenderer` the pool and `grids` live on.
102
+ * @param grids A `VDBGridNode` on this renderer with profile `'march'` and helpers including `'levelSet'`.
103
+ * @param gridId The level set's pool id (a number, made a `uint` uniform) or a `uint` node.
104
+ * @param params three's `MeshStandardMaterialParameters` plus the trace's ({@link VDBLevelSetMaterialParameters}).
105
+ * @throws VDBError `VDB_BAD_OPTION` for a `grids` this material can't use, a bad id or cap;
106
+ * `VDB_UNSUPPORTED_DEVICE` for an uninitialized renderer.
107
+ */
108
+ constructor(renderer: VDBThreeRendererLike, grids: VDBGridNode, gridId: TGridId, params?: VDBLevelSetMaterialParameters);
109
+ /** Lights read `positionView`: the shading point is the hit, not the box face. */
110
+ setupLighting(builder: Parameters<MeshStandardNodeMaterial["setupLighting"]>[0]): ReturnType<MeshStandardNodeMaterial["setupLighting"]>;
111
+ }
112
+ export {};
@@ -0,0 +1,204 @@
1
+ /**
2
+ * `VDBLevelSetMaterial`: a NanoVDB level set's zero surface, traced on the GPU
3
+ * on the sparse pool (K3.7, R1 §6 Step 7), as a three r187
4
+ * `MeshStandardNodeMaterial` (lights, shadows, depth, fog: three's own).
5
+ *
6
+ * const grids = new VDBGridNode(renderer, pool, { profile: 'march', helpers: ['levelSet'] });
7
+ * const material = new VDBLevelSetMaterial(renderer, grids, id, { color: 0xffffff, roughness: 0.5 });
8
+ * scene.add(new Mesh(vdbProxyGeometry(pool.info(id), { pad: 1 }), material));
9
+ * // per frame: pool.update(encoder) (or pool.flush()), then grids.update(), then render.
10
+ *
11
+ * Portions derived from mjurczyk/openvdb (MIT), commit 75e7345
12
+ * (`src/three-openvdb/levelset/webgpu/LevelSetSurfaceMaterial.js`,
13
+ * `LevelSetSurfaceCore.js`): the back-face proxy box (the camera can be
14
+ * inside), perspective and orthographic rays (so shadow passes work), the mask,
15
+ * depth, received-shadow position and the `setupLighting` override that moves
16
+ * `positionView` to the hit. Copyright (c) mjurczyk/openvdb contributors, MIT
17
+ * (see THIRD_PARTY_NOTICES.md). Changes: the trace is the core's `vdbLevelSetHit` on
18
+ * the sparse tree (HDDA skip, full-resolution trilinear SDF) instead of a
19
+ * sphere trace of a dense 8-bit texture; the ray comes from the pixel through
20
+ * the inverse projection, not from interpolated box positions; the normal is
21
+ * `vdbLevelSetNormal` (central differences at `normalStep` voxels through the
22
+ * grid affine); the proxy is in world space and the grid is placed with
23
+ * `pool.setTransform` (DIVERGES.md).
24
+ *
25
+ * The trace runs in the grid's index space: `o = worldToIndex(ray origin)`,
26
+ * `d = worldToIndexDir(unit world direction)`, so `t` is in world units. The
27
+ * ray is the pixel's (`viewportUV` through `cameraProjectionMatrixInverse`):
28
+ * perspective from `cameraPosition` over `t >= 0`; orthographic from the pixel
29
+ * on the camera plane along the view axis over `t` in `[-1e5, 1e5]`. The mesh
30
+ * must have an identity transform (the pool record holds the grid's
31
+ * placement); give it `vdbProxyGeometry(pool.info(id), { pad: 1 })`, which
32
+ * covers the trilinear support the trace clips to.
33
+ */
34
+ import * as THREE from "three";
35
+ import { MeshStandardNodeMaterial } from "three/webgpu";
36
+ import * as TSL from "three/tsl";
37
+ import { VDBError } from "../core/errors.js";
38
+ import { getDevice } from "./device.js";
39
+ import { VDBGridNode } from "./grid-node.js";
40
+ const { Fn, float, uniform, vec2, vec3, vec4, wgslFn, positionLocal, positionView, viewportUV } = TSL;
41
+ const { cameraFar, cameraNear, cameraPosition, cameraProjectionMatrix, cameraProjectionMatrixInverse, cameraViewMatrix, cameraWorldMatrix, modelViewMatrix } = TSL;
42
+ const { viewZToOrthographicDepth, viewZToPerspectiveDepth } = TSL;
43
+ /** Default compiled cap on the samples one fragment's trace takes (the live `maxSamples` clamps under it). */
44
+ export const VDB_LEVEL_SET_SAMPLES_CAP = 1024;
45
+ const TRACE = "vdbThreeLevelSetTrace";
46
+ const NORMAL = "vdbThreeLevelSetNormal";
47
+ function traceWgsl(cap) {
48
+ return /* wgsl */ `fn ${TRACE}(grid_id: u32, origin_w: vec3f, dir_w: vec3f, t_range: vec2f, sdf_to_index: f32, max_samples: f32) -> vec4f {
49
+ let o = vdbWorldToIndex(grid_id, origin_w);
50
+ let d = vdbWorldToIndexDir(grid_id, dir_w);
51
+ var span = t_range;
52
+ let n = u32(clamp(max_samples, 1.0, ${cap}.0));
53
+ if !vdbLevelSetHit(grid_id, o, d, &span, sdf_to_index, n) {
54
+ return vec4f(0.0);
55
+ }
56
+ return vec4f(origin_w + dir_w * span.x, 1.0);
57
+ }`;
58
+ }
59
+ const NORMAL_WGSL = /* wgsl */ `fn ${NORMAL}(grid_id: u32, p_w: vec3f, h: f32) -> vec3f {
60
+ return vdbLevelSetNormal(grid_id, vdbWorldToIndex(grid_id, p_w), h);
61
+ }`;
62
+ function bad(message) {
63
+ return new VDBError("VDB_BAD_OPTION", `VDBLevelSetMaterial: ${message}`);
64
+ }
65
+ /**
66
+ * A level set's surface on a world-space proxy box (see the file comment).
67
+ * Shades as a `MeshStandardNodeMaterial`: `color`, `roughness`, `metalness`,
68
+ * maps-free; lights and shadows read the hit point.
69
+ *
70
+ * - Exposes the trace as TSL nodes for custom shading or debugging:
71
+ * {@link hitWorldNode}, {@link hitViewNode}, {@link hitMaskNode},
72
+ * {@link normalWorldNode}, {@link normalViewNode} (e.g. `material.colorNode =
73
+ * material.normalViewNode.mul(0.5).add(0.5)` with no lights shows the normals).
74
+ * - Perspective and orthographic cameras (directional-light shadow maps).
75
+ *
76
+ * @typeParam TGridId What the constructor got as the id: a number (default)
77
+ * makes {@link gridId} a `uint` uniform; a node is kept as given.
78
+ */
79
+ export class VDBLevelSetMaterial extends MeshStandardNodeMaterial {
80
+ isVDBLevelSetMaterial = true;
81
+ /** The pool node this material reads. */
82
+ grids;
83
+ /** The grid id: a `uint` uniform for a numeric id (`material.gridId.value = otherId`), else the caller's node. */
84
+ gridId;
85
+ /** Index voxels per SDF unit (live). */
86
+ sdfToIndex;
87
+ /** Trilinear samples per trace (live, clamped to the compiled cap). */
88
+ maxSamples;
89
+ /** Central-difference step of the normal in index voxels (live). */
90
+ normalStep;
91
+ /** The trace entry's WGSL (for inspection and tests). */
92
+ traceSource;
93
+ /** `vec4(hit world position, 1)` on a hit, `vec4(0)` on a miss (fragment stage). */
94
+ traceNode;
95
+ /** The hit in world space. */
96
+ hitWorldNode;
97
+ /** The hit in view space. */
98
+ hitViewNode;
99
+ /** True where the ray hit the surface (the material's `maskNode`). */
100
+ hitMaskNode;
101
+ /** World-space unit normal at the hit. */
102
+ normalWorldNode;
103
+ /** View-space unit normal at the hit (the material's `normalNode`). */
104
+ normalViewNode;
105
+ /**
106
+ * @param renderer The initialized `WebGPURenderer` the pool and `grids` live on.
107
+ * @param grids A `VDBGridNode` on this renderer with profile `'march'` and helpers including `'levelSet'`.
108
+ * @param gridId The level set's pool id (a number, made a `uint` uniform) or a `uint` node.
109
+ * @param params three's `MeshStandardMaterialParameters` plus the trace's ({@link VDBLevelSetMaterialParameters}).
110
+ * @throws VDBError `VDB_BAD_OPTION` for a `grids` this material can't use, a bad id or cap;
111
+ * `VDB_UNSUPPORTED_DEVICE` for an uninitialized renderer.
112
+ */
113
+ constructor(renderer, grids, gridId, params = {}) {
114
+ const { sdfToIndex, maxSamples, maxSamplesCap, normalStep, ...standard } = params;
115
+ super(standard);
116
+ this.name = "VDBLevelSetMaterial";
117
+ if (!(grids instanceof VDBGridNode))
118
+ throw bad("grids must be a VDBGridNode.");
119
+ getDevice(renderer);
120
+ if (grids.renderer !== renderer) {
121
+ throw bad("grids was made for another renderer: create one VDBGridNode per renderer.");
122
+ }
123
+ if (grids.options.profile !== "march" || !grids.options.helpers?.includes("levelSet")) {
124
+ throw bad("grids needs profile 'march' and the 'levelSet' helper: new VDBGridNode(renderer, pool, { profile: 'march', helpers: ['levelSet'] }).");
125
+ }
126
+ if (typeof gridId === "number") {
127
+ if (!Number.isInteger(gridId) || gridId < 0)
128
+ throw bad(`gridId must be a non-negative integer, got ${gridId}.`);
129
+ }
130
+ else if (gridId === null || typeof gridId !== "object") {
131
+ throw bad("gridId must be a number or a uint TSL node.");
132
+ }
133
+ const cap = maxSamplesCap ?? VDB_LEVEL_SET_SAMPLES_CAP;
134
+ if (!Number.isInteger(cap) || cap < 1)
135
+ throw bad(`maxSamplesCap must be an integer >= 1, got ${JSON.stringify(maxSamplesCap)}.`);
136
+ let toIndex = sdfToIndex;
137
+ if (toIndex === undefined) {
138
+ const info = typeof gridId === "number" ? grids.pool.info?.(gridId) : undefined;
139
+ toIndex = info ? 1 / info.voxelSize[0] : 1;
140
+ }
141
+ if (!(Number.isFinite(toIndex) && toIndex > 0))
142
+ throw bad(`sdfToIndex must be a positive finite number, got ${toIndex}.`);
143
+ this.grids = grids;
144
+ this.gridId = (typeof gridId === "number" ? uniform(gridId, "uint") : gridId);
145
+ this.sdfToIndex = uniform(toIndex);
146
+ this.maxSamples = uniform(maxSamples ?? 512);
147
+ this.normalStep = uniform(normalStep ?? 1);
148
+ this.traceSource = traceWgsl(cap);
149
+ const traceFn = wgslFn(this.traceSource, [grids.module]);
150
+ const normalFn = wgslFn(NORMAL_WGSL, [grids.module]);
151
+ // The pixel's view ray, from the fragment's viewport position through the inverse projection (not from
152
+ // interpolated box positions, whose varying precision moves the ray by ~0.02 px on large faces). Perspective:
153
+ // from the camera, t >= 0. Orthographic (directional-light shadow maps): from the pixel on the camera plane
154
+ // along the view axis, t in [-1e5, 1e5].
155
+ const ray = (builder) => {
156
+ const uv = viewportUV;
157
+ const ndc = vec2(uv.x.mul(2.0).sub(1.0), float(1.0).sub(uv.y.mul(2.0)));
158
+ const clip = cameraProjectionMatrixInverse.mul(vec4(ndc, 0.5, 1.0));
159
+ const view = clip.xyz.div(clip.w);
160
+ const ortho = builder.camera?.isOrthographicCamera === true;
161
+ const dirView = ortho ? vec3(0.0, 0.0, -1.0) : view.normalize();
162
+ const origin = ortho ? cameraWorldMatrix.mul(vec4(view.x, view.y, 0.0, 1.0)).xyz : cameraPosition;
163
+ const dir = cameraWorldMatrix.mul(vec4(dirView, 0.0)).xyz.normalize();
164
+ return { origin, dir, range: ortho ? vec2(-1e5, 1e5) : vec2(0.0, 1e30) };
165
+ };
166
+ this.traceNode = Fn((builder) => {
167
+ const r = ray(builder);
168
+ return traceFn({
169
+ grid_id: this.gridId,
170
+ origin_w: r.origin,
171
+ dir_w: r.dir,
172
+ t_range: r.range,
173
+ sdf_to_index: this.sdfToIndex,
174
+ max_samples: this.maxSamples,
175
+ });
176
+ })
177
+ .once()()
178
+ .toVar("vdbLevelSetTrace");
179
+ this.hitWorldNode = this.traceNode.xyz;
180
+ this.hitMaskNode = this.traceNode.w.greaterThan(0.5);
181
+ this.hitViewNode = cameraViewMatrix.mul(vec4(this.hitWorldNode, 1.0)).xyz.toVar("vdbLevelSetHitView");
182
+ this.normalWorldNode = Fn(() => normalFn({ grid_id: this.gridId, p_w: this.hitWorldNode, h: this.normalStep }))
183
+ .once()()
184
+ .toVar("vdbLevelSetNormalWorld");
185
+ this.normalViewNode = cameraViewMatrix.mul(vec4(this.normalWorldNode, 0.0)).xyz.normalize();
186
+ this.side = THREE.BackSide;
187
+ this.shadowSide = THREE.BackSide;
188
+ this.maskNode = this.hitMaskNode;
189
+ // A vertexNode makes the fragment's positionView a variable, which setupLighting moves to the hit.
190
+ this.vertexNode = cameraProjectionMatrix.mul(modelViewMatrix.mul(vec4(positionLocal, 1.0)));
191
+ const hitView = this.hitViewNode;
192
+ this.depthNode = Fn((builder) => builder.camera?.isOrthographicCamera
193
+ ? viewZToOrthographicDepth(hitView.z, cameraNear, cameraFar)
194
+ : viewZToPerspectiveDepth(hitView.z, cameraNear, cameraFar))();
195
+ this.receivedShadowPositionNode = this.hitWorldNode;
196
+ this.normalNode = this.normalViewNode;
197
+ }
198
+ /** Lights read `positionView`: the shading point is the hit, not the box face. */
199
+ setupLighting(builder) {
200
+ positionView.assign(this.hitViewNode).toStack();
201
+ return super.setupLighting(builder);
202
+ }
203
+ }
204
+ //# sourceMappingURL=level-set-material.js.map
@@ -0,0 +1 @@
1
+ {"version":3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C,YAAY,CAAC;QACpD,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,cAAc,CAAC;IACxC,CAAC;IAED,kFAAkF;IACzE,aAAa,CAAC,OAAiE;QACtF,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,OAAO,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC;CACF","sourcesContent":["/**\n * `VDBLevelSetMaterial`: a NanoVDB level set's zero surface, traced on the GPU\n * on the sparse pool (K3.7, R1 §6 Step 7), as a three r187\n * `MeshStandardNodeMaterial` (lights, shadows, depth, fog: three's own).\n *\n * const grids = new VDBGridNode(renderer, pool, { profile: 'march', helpers: ['levelSet'] });\n * const material = new VDBLevelSetMaterial(renderer, grids, id, { color: 0xffffff, roughness: 0.5 });\n * scene.add(new Mesh(vdbProxyGeometry(pool.info(id), { pad: 1 }), material));\n * // per frame: pool.update(encoder) (or pool.flush()), then grids.update(), then render.\n *\n * Portions derived from mjurczyk/openvdb (MIT), commit 75e7345\n * (`src/three-openvdb/levelset/webgpu/LevelSetSurfaceMaterial.js`,\n * `LevelSetSurfaceCore.js`): the back-face proxy box (the camera can be\n * inside), perspective and orthographic rays (so shadow passes work), the mask,\n * depth, received-shadow position and the `setupLighting` override that moves\n * `positionView` to the hit. Copyright (c) mjurczyk/openvdb contributors, MIT\n * (see THIRD_PARTY_NOTICES.md). Changes: the trace is the core's `vdbLevelSetHit` on\n * the sparse tree (HDDA skip, full-resolution trilinear SDF) instead of a\n * sphere trace of a dense 8-bit texture; the ray comes from the pixel through\n * the inverse projection, not from interpolated box positions; the normal is\n * `vdbLevelSetNormal` (central differences at `normalStep` voxels through the\n * grid affine); the proxy is in world space and the grid is placed with\n * `pool.setTransform` (DIVERGES.md).\n *\n * The trace runs in the grid's index space: `o = worldToIndex(ray origin)`,\n * `d = worldToIndexDir(unit world direction)`, so `t` is in world units. The\n * ray is the pixel's (`viewportUV` through `cameraProjectionMatrixInverse`):\n * perspective from `cameraPosition` over `t >= 0`; orthographic from the pixel\n * on the camera plane along the view axis over `t` in `[-1e5, 1e5]`. The mesh\n * must have an identity transform (the pool record holds the grid's\n * placement); give it `vdbProxyGeometry(pool.info(id), { pad: 1 })`, which\n * covers the trilinear support the trace clips to.\n */\n\nimport * as THREE from \"three\";\nimport { MeshStandardNodeMaterial } from \"three/webgpu\";\nimport * as TSL from \"three/tsl\";\nimport { VDBError } from \"../core/errors.js\";\nimport { getDevice, type VDBThreeRendererLike } from \"./device.js\";\nimport { VDBGridNode, type VDBTslNode } from \"./grid-node.js\";\nimport type { VDBUintUniform } from \"./material.js\";\n\nconst { Fn, float, uniform, vec2, vec3, vec4, wgslFn, positionLocal, positionView, viewportUV } = TSL as unknown as Record<string, VDBTslNode>;\nconst { cameraFar, cameraNear, cameraPosition, cameraProjectionMatrix, cameraProjectionMatrixInverse, cameraViewMatrix, cameraWorldMatrix, modelViewMatrix } =\n TSL as unknown as Record<string, VDBTslNode>;\nconst { viewZToOrthographicDepth, viewZToPerspectiveDepth } = TSL as unknown as Record<string, VDBTslNode>;\n\n/** Default compiled cap on the samples one fragment's trace takes (the live `maxSamples` clamps under it). */\nexport const VDB_LEVEL_SET_SAMPLES_CAP = 1024;\n\n/** Parameters of {@link VDBLevelSetMaterial}: three's standard material parameters plus the trace's. */\nexport interface VDBLevelSetMaterialParameters extends THREE.MeshStandardMaterialParameters {\n /**\n * Index voxels per SDF unit. Default: `1 / voxelSize.x` from `grids.pool.info(id)` when the pool\n * has `info` and the id is a number, else 1. A level set stores distances in its own world units,\n * so this is 1 / its NanoVDB voxel size.\n */\n sdfToIndex?: number;\n /** Trilinear samples per fragment trace (live), clamped to `[1, maxSamplesCap]`. Default 512. */\n maxSamples?: number;\n /** Compiled cap on {@link maxSamples}. Default {@link VDB_LEVEL_SET_SAMPLES_CAP}. */\n maxSamplesCap?: number;\n /** Central-difference step of the normal, in index voxels (live). Default 1. */\n normalStep?: number;\n}\n\ntype ScalarUniform = ReturnType<typeof TSL.uniform> & { value: number };\n\nconst TRACE = \"vdbThreeLevelSetTrace\";\nconst NORMAL = \"vdbThreeLevelSetNormal\";\n\nfunction traceWgsl(cap: number): string {\n return /* wgsl */ `fn ${TRACE}(grid_id: u32, origin_w: vec3f, dir_w: vec3f, t_range: vec2f, sdf_to_index: f32, max_samples: f32) -> vec4f {\n let o = vdbWorldToIndex(grid_id, origin_w);\n let d = vdbWorldToIndexDir(grid_id, dir_w);\n var span = t_range;\n let n = u32(clamp(max_samples, 1.0, ${cap}.0));\n if !vdbLevelSetHit(grid_id, o, d, &span, sdf_to_index, n) {\n return vec4f(0.0);\n }\n return vec4f(origin_w + dir_w * span.x, 1.0);\n}`;\n}\n\nconst NORMAL_WGSL = /* wgsl */ `fn ${NORMAL}(grid_id: u32, p_w: vec3f, h: f32) -> vec3f {\n return vdbLevelSetNormal(grid_id, vdbWorldToIndex(grid_id, p_w), h);\n}`;\n\nfunction bad(message: string): VDBError {\n return new VDBError(\"VDB_BAD_OPTION\", `VDBLevelSetMaterial: ${message}`);\n}\n\n/**\n * A level set's surface on a world-space proxy box (see the file comment).\n * Shades as a `MeshStandardNodeMaterial`: `color`, `roughness`, `metalness`,\n * maps-free; lights and shadows read the hit point.\n *\n * - Exposes the trace as TSL nodes for custom shading or debugging:\n * {@link hitWorldNode}, {@link hitViewNode}, {@link hitMaskNode},\n * {@link normalWorldNode}, {@link normalViewNode} (e.g. `material.colorNode =\n * material.normalViewNode.mul(0.5).add(0.5)` with no lights shows the normals).\n * - Perspective and orthographic cameras (directional-light shadow maps).\n *\n * @typeParam TGridId What the constructor got as the id: a number (default)\n * makes {@link gridId} a `uint` uniform; a node is kept as given.\n */\nexport class VDBLevelSetMaterial<TGridId extends number | VDBTslNode = number> extends MeshStandardNodeMaterial {\n readonly isVDBLevelSetMaterial = true;\n /** The pool node this material reads. */\n readonly grids: VDBGridNode;\n /** The grid id: a `uint` uniform for a numeric id (`material.gridId.value = otherId`), else the caller's node. */\n readonly gridId: TGridId extends number ? VDBUintUniform : VDBTslNode;\n /** Index voxels per SDF unit (live). */\n readonly sdfToIndex: ScalarUniform;\n /** Trilinear samples per trace (live, clamped to the compiled cap). */\n readonly maxSamples: ScalarUniform;\n /** Central-difference step of the normal in index voxels (live). */\n readonly normalStep: ScalarUniform;\n /** The trace entry's WGSL (for inspection and tests). */\n readonly traceSource: string;\n /** `vec4(hit world position, 1)` on a hit, `vec4(0)` on a miss (fragment stage). */\n readonly traceNode: VDBTslNode;\n /** The hit in world space. */\n readonly hitWorldNode: VDBTslNode;\n /** The hit in view space. */\n readonly hitViewNode: VDBTslNode;\n /** True where the ray hit the surface (the material's `maskNode`). */\n readonly hitMaskNode: VDBTslNode;\n /** World-space unit normal at the hit. */\n readonly normalWorldNode: VDBTslNode;\n /** View-space unit normal at the hit (the material's `normalNode`). */\n readonly normalViewNode: VDBTslNode;\n\n /**\n * @param renderer The initialized `WebGPURenderer` the pool and `grids` live on.\n * @param grids A `VDBGridNode` on this renderer with profile `'march'` and helpers including `'levelSet'`.\n * @param gridId The level set's pool id (a number, made a `uint` uniform) or a `uint` node.\n * @param params three's `MeshStandardMaterialParameters` plus the trace's ({@link VDBLevelSetMaterialParameters}).\n * @throws VDBError `VDB_BAD_OPTION` for a `grids` this material can't use, a bad id or cap;\n * `VDB_UNSUPPORTED_DEVICE` for an uninitialized renderer.\n */\n constructor(renderer: VDBThreeRendererLike, grids: VDBGridNode, gridId: TGridId, params: VDBLevelSetMaterialParameters = {}) {\n const { sdfToIndex, maxSamples, maxSamplesCap, normalStep, ...standard } = params;\n super(standard);\n this.name = \"VDBLevelSetMaterial\";\n if (!(grids instanceof VDBGridNode)) throw bad(\"grids must be a VDBGridNode.\");\n getDevice(renderer);\n if (grids.renderer !== renderer) {\n throw bad(\"grids was made for another renderer: create one VDBGridNode per renderer.\");\n }\n if (grids.options.profile !== \"march\" || !grids.options.helpers?.includes(\"levelSet\")) {\n throw bad(\"grids needs profile 'march' and the 'levelSet' helper: new VDBGridNode(renderer, pool, { profile: 'march', helpers: ['levelSet'] }).\");\n }\n if (typeof gridId === \"number\") {\n if (!Number.isInteger(gridId) || gridId < 0) throw bad(`gridId must be a non-negative integer, got ${gridId}.`);\n } else if (gridId === null || typeof gridId !== \"object\") {\n throw bad(\"gridId must be a number or a uint TSL node.\");\n }\n const cap = maxSamplesCap ?? VDB_LEVEL_SET_SAMPLES_CAP;\n if (!Number.isInteger(cap) || cap < 1) throw bad(`maxSamplesCap must be an integer >= 1, got ${JSON.stringify(maxSamplesCap)}.`);\n let toIndex = sdfToIndex;\n if (toIndex === undefined) {\n const info = typeof gridId === \"number\" ? (grids.pool as { info?: (id: number) => { voxelSize: readonly number[] } }).info?.(gridId) : undefined;\n toIndex = info ? 1 / info.voxelSize[0]! : 1;\n }\n if (!(Number.isFinite(toIndex) && toIndex > 0)) throw bad(`sdfToIndex must be a positive finite number, got ${toIndex}.`);\n\n this.grids = grids;\n this.gridId = (typeof gridId === \"number\" ? uniform(gridId, \"uint\") : gridId) as this[\"gridId\"];\n this.sdfToIndex = uniform(toIndex) as ScalarUniform;\n this.maxSamples = uniform(maxSamples ?? 512) as ScalarUniform;\n this.normalStep = uniform(normalStep ?? 1) as ScalarUniform;\n this.traceSource = traceWgsl(cap);\n\n const traceFn = wgslFn(this.traceSource, [grids.module] as never);\n const normalFn = wgslFn(NORMAL_WGSL, [grids.module] as never);\n\n // The pixel's view ray, from the fragment's viewport position through the inverse projection (not from\n // interpolated box positions, whose varying precision moves the ray by ~0.02 px on large faces). Perspective:\n // from the camera, t >= 0. Orthographic (directional-light shadow maps): from the pixel on the camera plane\n // along the view axis, t in [-1e5, 1e5].\n const ray = (builder: { camera?: { isOrthographicCamera?: boolean } }) => {\n const uv = viewportUV;\n const ndc = vec2(uv.x.mul(2.0).sub(1.0), float(1.0).sub(uv.y.mul(2.0)));\n const clip = cameraProjectionMatrixInverse.mul(vec4(ndc, 0.5, 1.0));\n const view = clip.xyz.div(clip.w);\n const ortho = builder.camera?.isOrthographicCamera === true;\n const dirView = ortho ? vec3(0.0, 0.0, -1.0) : view.normalize();\n const origin = ortho ? cameraWorldMatrix.mul(vec4(view.x, view.y, 0.0, 1.0)).xyz : cameraPosition;\n const dir = cameraWorldMatrix.mul(vec4(dirView, 0.0)).xyz.normalize();\n return { origin, dir, range: ortho ? vec2(-1e5, 1e5) : vec2(0.0, 1e30) };\n };\n this.traceNode = Fn((builder: { camera?: { isOrthographicCamera?: boolean } }) => {\n const r = ray(builder);\n return traceFn({\n grid_id: this.gridId,\n origin_w: r.origin,\n dir_w: r.dir,\n t_range: r.range,\n sdf_to_index: this.sdfToIndex,\n max_samples: this.maxSamples,\n });\n })\n .once()()\n .toVar(\"vdbLevelSetTrace\");\n this.hitWorldNode = this.traceNode.xyz;\n this.hitMaskNode = this.traceNode.w.greaterThan(0.5);\n this.hitViewNode = cameraViewMatrix.mul(vec4(this.hitWorldNode, 1.0)).xyz.toVar(\"vdbLevelSetHitView\");\n this.normalWorldNode = Fn(() => normalFn({ grid_id: this.gridId, p_w: this.hitWorldNode, h: this.normalStep }))\n .once()()\n .toVar(\"vdbLevelSetNormalWorld\");\n this.normalViewNode = cameraViewMatrix.mul(vec4(this.normalWorldNode, 0.0)).xyz.normalize();\n\n this.side = THREE.BackSide;\n this.shadowSide = THREE.BackSide;\n this.maskNode = this.hitMaskNode;\n // A vertexNode makes the fragment's positionView a variable, which setupLighting moves to the hit.\n this.vertexNode = cameraProjectionMatrix.mul(modelViewMatrix.mul(vec4(positionLocal, 1.0)));\n const hitView = this.hitViewNode;\n this.depthNode = Fn((builder: { camera?: { isOrthographicCamera?: boolean } }) =>\n builder.camera?.isOrthographicCamera\n ? viewZToOrthographicDepth(hitView.z, cameraNear, cameraFar)\n : viewZToPerspectiveDepth(hitView.z, cameraNear, cameraFar),\n )();\n this.receivedShadowPositionNode = this.hitWorldNode;\n this.normalNode = this.normalViewNode;\n }\n\n /** Lights read `positionView`: the shading point is the hit, not the box face. */\n override setupLighting(builder: Parameters<MeshStandardNodeMaterial[\"setupLighting\"]>[0]): ReturnType<MeshStandardNodeMaterial[\"setupLighting\"]> {\n positionView.assign(this.hitViewNode).toStack();\n return super.setupLighting(builder);\n }\n}\n"]}