@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,548 @@
1
+ /**
2
+ * `VDBSequence`: manifest-driven animated-volume playback on a `VDBGridPool`
3
+ * (task K2.3; v1's `NanoVDBSequence`, docs/archive/v1/SPEC.md §3.5). Decodes per-frame grid
4
+ * images ahead of time into a bounded prefetch ring and swaps the shown one
5
+ * into ONE pool id with `pool.replace(id, image)`.
6
+ *
7
+ * ## The pool contract
8
+ *
9
+ * const id = pool.add(firstFrame, { capacity: largestFrameBytes });
10
+ * sequence.start({ pool, id });
11
+ * // every frame:
12
+ * sequence.update(performance.now()); // may call pool.replace(id, frame)
13
+ * pool.update(encoder) / pool.flush(); // writes the frame in place
14
+ * grids.update(); // VDBGridNode: rebinds only after a growth
15
+ * renderer.render(scene, camera);
16
+ *
17
+ * Reserve `capacity` for the largest frame: every `replace` then writes in
18
+ * place (no move, no `pool.version` change, no rebind, no new bind group). A
19
+ * frame larger than the capacity still works, but it moves the image, and the
20
+ * next `update` may grow the pool (a `version` bump), so keep calling
21
+ * `grids.update()` after the pool's update either way.
22
+ *
23
+ * **Frame arrays are held by reference.** `replace` keeps the image until the
24
+ * `update` that writes it, and until `pool.settled()` resolves while a growth
25
+ * is unconfirmed (the pool may have to stage it again after a rollback). The
26
+ * player never writes into a frame array, and its ring only drops references.
27
+ * A custom `loader` that recycles frame buffers must not reuse an array it
28
+ * returned before `await pool.settled()` after the update that wrote it.
29
+ *
30
+ * ## Design for testability (the scheduler is a pure clock consumer)
31
+ *
32
+ * The player never owns the animation loop or reads the wall clock itself.
33
+ * `update(now)` takes the current time in ms; the consumer calls it from its
34
+ * own `requestAnimationFrame` loop with `performance.now()`, and tests call it
35
+ * with a fake, hand-advanced clock. The pool is reached only through
36
+ * `replace(id, image)`, so tests pass a stub.
37
+ *
38
+ * ## Stall policy: never block the render loop
39
+ *
40
+ * If the frame that is due hasn't finished decoding, `update()` does not wait:
41
+ * it holds the last-shown frame, counts a stall, and returns. Decoding
42
+ * continues in the background; the next `update()` that finds the frame ready
43
+ * advances to wherever the clock now points (intermediate frames are dropped:
44
+ * real-time catch-up, not slow motion).
45
+ *
46
+ * ## Frame range and loop mode
47
+ *
48
+ * `range: [start, end]` (inclusive frame indices) limits playback to those frames; the default is all of them.
49
+ * `loopMode: 'repeat'` (default) wraps from `end` to `start`; `'pingpong'` plays forward then backward
50
+ * (`start .. end .. start`), with each end frame shown once per turn (no doubled frame at the ends); `'once'` plays
51
+ * to `end` and holds there. `start()` shows `range[0]`. `seek(i)` wraps `i` into the clip, then clamps it into the
52
+ * range. `setRange()` and `setLoopMode()` change them while playing (playback continues from the shown frame,
53
+ * clamped into the new range). The prefetch ring follows the playback order, so a swap is always a `pool.replace`
54
+ * of a frame the ring already holds.
55
+ *
56
+ * **Direction.** A ping-pong keeps its direction across `stop()` / `resume()`, `seek()` and `setRange()`: paused on
57
+ * the way back, it resumes on the way back. `start()` goes forward; `setLoopMode()` keeps the direction only when the
58
+ * new mode is `'pingpong'` (`'repeat'` and `'once'` only go forward).
59
+ *
60
+ * ## Failed frames: no retry until `seek` / `start`
61
+ *
62
+ * A frame whose loader rejects goes into a failed set: `onError` fires once,
63
+ * and the player does not ask the loader for it again (no retry storm from
64
+ * the per-frame prefetch). While the clock points at it, `update()` holds the
65
+ * last frame and counts stalls; playback moves on when the clock reaches the
66
+ * next decodable frame. `seek()` and `start()` clear the set, so they retry
67
+ * every failed frame (call `seek(stats.frame)` to retry in place).
68
+ * `stats.failed` counts the frames in the set.
69
+ *
70
+ * ## Disposal
71
+ *
72
+ * `dispose()` drops the ring and the in-flight tracking and bumps a
73
+ * generation token: decodes that finish later are dropped (no ring entry, no
74
+ * `onError`). `start`, `seek`, `resume` and `preload` after `dispose()` throw
75
+ * (or reject with) `VDB_DISPOSED`; `update` returns the last frame.
76
+ */
77
+ import { VDBError } from "./errors.js";
78
+ import { NvdbFile } from "../tools/nvdb-file.js";
79
+ const LOOP_MODES = ["once", "repeat", "pingpong"];
80
+ /** Default loader: real fetch + parse of grid 0. */
81
+ async function defaultLoader(url) {
82
+ const file = await NvdbFile.fromURL(url);
83
+ return file.gridImage(0);
84
+ }
85
+ /**
86
+ * Plays a frame sequence into ONE pool grid: decodes frames ahead into a
87
+ * bounded ring and `pool.replace`s the due one, driven by your clock. See the
88
+ * file comment for the pool contract, the stall policy, failed frames and
89
+ * disposal.
90
+ *
91
+ * const id = pool.add(firstFrame, { capacity: largestFrameBytes });
92
+ * const sequence = new VDBSequence({ urls, fps: 24 });
93
+ * sequence.start({ pool, id });
94
+ * // per frame: sequence.update(performance.now()); pool.update(encoder); grids.update(); render
95
+ */
96
+ export class VDBSequence {
97
+ /** Total frames of the clip. */
98
+ frameCount;
99
+ /** Playback rate in frames per second. */
100
+ fps;
101
+ /** How many frames are decoded ahead of the shown one. */
102
+ prefetch;
103
+ _rangeStart = 0;
104
+ _rangeEnd = 0;
105
+ _loopMode = "repeat";
106
+ /** Playback direction at the shown frame: +1, or -1 on the way back of a ping-pong. */
107
+ _dir = 1;
108
+ /** Direction at the clock anchor (`startFrame`): -1 when it was anchored on the way back of a ping-pong. */
109
+ startDir = 1;
110
+ urlFor;
111
+ loader;
112
+ hasLoader;
113
+ now;
114
+ onFrame;
115
+ onError;
116
+ frameDurationMs;
117
+ /** Decoded frame images by frame index. */
118
+ ring = new Map();
119
+ /** In-flight decode promises by frame index (dedupe + stall detection). */
120
+ inflight = new Map();
121
+ /** Frames whose decode failed: not retried until `seek` / `start`. */
122
+ failed = new Set();
123
+ /** Bumped by `dispose()`: a decode that finishes under an older generation is dropped. */
124
+ generation = 0;
125
+ disposed = false;
126
+ replaceFrame;
127
+ /** K5.9: a frame shown by `seek` while stopped once its decode lands. */
128
+ pendingFrame = -1;
129
+ /** The playback direction at `pendingFrame`. */
130
+ pendingDir = 1;
131
+ /** `pendingFrame` was asked for (start / seek / a range or mode change), not made due by the clock: it survives `stop()`. */
132
+ pendingExplicit = false;
133
+ playing = false;
134
+ startNow = 0;
135
+ startFrame = 0;
136
+ _frame = -1;
137
+ _stalls = 0;
138
+ _replaceMs = 0;
139
+ _swaps = 0;
140
+ /**
141
+ * Creates the player; nothing is loaded until `start`.
142
+ *
143
+ * @param opts URLs, frame count, rate, prefetch, range, loop mode, loader, clock and callbacks.
144
+ */
145
+ constructor(opts) {
146
+ const frameCount = opts.frameCount ?? (Array.isArray(opts.urls) ? opts.urls.length : undefined);
147
+ if (frameCount === undefined || !Number.isInteger(frameCount) || frameCount < 1) {
148
+ throw new VDBError("VDB_BAD_OPTION", "VDBSequence: `frameCount` is required (a positive integer) when `urls` is a function; " +
149
+ "with an array of urls it defaults to urls.length.");
150
+ }
151
+ this.frameCount = frameCount;
152
+ this.fps = opts.fps ?? 24;
153
+ if (!(this.fps > 0))
154
+ throw new VDBError("VDB_BAD_OPTION", `VDBSequence: fps must be > 0 (got ${this.fps}).`);
155
+ this.prefetch = Math.max(0, opts.prefetch ?? 3);
156
+ this._rangeEnd = frameCount - 1;
157
+ if (opts.range !== undefined)
158
+ this.checkRange(opts.range, "VDBSequence");
159
+ this._loopMode = this.checkLoopMode(opts.loopMode ?? "repeat", "VDBSequence");
160
+ this.frameDurationMs = 1000 / this.fps;
161
+ const urls = opts.urls;
162
+ this.urlFor = typeof urls === "function" ? urls : (i) => urls[i] ?? "";
163
+ this.hasLoader = !!opts.loader;
164
+ this.loader = opts.loader ?? defaultLoader;
165
+ this.now = opts.now ?? (() => performance.now());
166
+ this.onFrame = opts.onFrame;
167
+ this.onError = opts.onError;
168
+ }
169
+ /** A snapshot of the playback counters. */
170
+ get stats() {
171
+ return {
172
+ frame: this._frame,
173
+ decodedAhead: this.decodedAhead(),
174
+ stalls: this._stalls,
175
+ replaceMs: this._replaceMs,
176
+ swaps: this._swaps,
177
+ failed: this.failed.size,
178
+ };
179
+ }
180
+ /** True while the clock is running: after `start` or `resume`, until `stop`. */
181
+ get isPlaying() {
182
+ return this.playing;
183
+ }
184
+ /** Wrap a raw (possibly negative or >= frameCount) index into [0, frameCount). */
185
+ wrap(index) {
186
+ const n = this.frameCount;
187
+ return ((index % n) + n) % n;
188
+ }
189
+ /** The playback range, inclusive: `[0, frameCount - 1]` unless set. */
190
+ get range() {
191
+ return [this._rangeStart, this._rangeEnd];
192
+ }
193
+ /** What playback does at the range end (`'repeat'` unless set). */
194
+ get loopMode() {
195
+ return this._loopMode;
196
+ }
197
+ checkRange(range, who) {
198
+ const [a, b] = Array.isArray(range) ? range : [NaN, NaN];
199
+ if (!Number.isInteger(a) || !Number.isInteger(b) || a < 0 || b < a || b >= this.frameCount) {
200
+ throw new VDBError("VDB_BAD_OPTION", `${who}: range must be [start, end] integers with 0 <= start <= end < frameCount (${this.frameCount}); got ${JSON.stringify(range)}.`);
201
+ }
202
+ this._rangeStart = a;
203
+ this._rangeEnd = b;
204
+ }
205
+ checkLoopMode(mode, who) {
206
+ if (!LOOP_MODES.includes(mode)) {
207
+ throw new VDBError("VDB_BAD_OPTION", `${who}: loopMode must be 'once', 'repeat' or 'pingpong' (got ${String(mode)}).`);
208
+ }
209
+ return mode;
210
+ }
211
+ /**
212
+ * Change the playback range (inclusive). While playing, playback continues from the shown frame, clamped into the
213
+ * new range (the clock re-anchors there; a ping-pong keeps its direction); the prefetch ring is refilled in the
214
+ * new order.
215
+ *
216
+ * @param range Inclusive `[start, end]` frame range.
217
+ * @param now Clock time in ms to re-anchor at (default: the injected clock).
218
+ *
219
+ * @throws VDBError `VDB_BAD_OPTION` for a bad range; `VDB_DISPOSED` after `dispose()`.
220
+ */
221
+ setRange(range, now = this.now()) {
222
+ this.assertLive("setRange()");
223
+ this.checkRange(range, "VDBSequence.setRange");
224
+ this.reanchor(now);
225
+ }
226
+ /**
227
+ * Change what playback does at the range end. Playback continues from the shown frame: going forward, or, when
228
+ * both the old and the new mode are `'pingpong'`, in its current direction. Switching to `'once'` at the range end
229
+ * holds there; switching from `'once'` held at the end to `'repeat'` or `'pingpong'` plays on.
230
+ *
231
+ * @param mode `'once'`, `'repeat'` or `'pingpong'`.
232
+ * @param now Clock time in ms to re-anchor at (default: the injected clock).
233
+ *
234
+ * @throws VDBError `VDB_BAD_OPTION` for an unknown mode; `VDB_DISPOSED` after `dispose()`.
235
+ */
236
+ setLoopMode(mode, now = this.now()) {
237
+ this.assertLive("setLoopMode()");
238
+ this._loopMode = this.checkLoopMode(mode, "VDBSequence.setLoopMode");
239
+ if (this._loopMode !== "pingpong")
240
+ this._dir = 1;
241
+ this.reanchor(now);
242
+ }
243
+ /** Re-anchor the clock at the shown frame (clamped into the range) after a range or mode change. */
244
+ reanchor(now) {
245
+ this.anchor(this._frame < 0 ? this._rangeStart : this._frame, this._dir, now);
246
+ if (!this.replaceFrame)
247
+ return;
248
+ this.ensurePrefetch(this.startFrame, this.startDir);
249
+ if (this._frame < 0 || this._frame !== this.startFrame)
250
+ this.showFrame(this.startFrame, this.startDir, true);
251
+ }
252
+ /** Anchor the clock at `frame` (clamped into the range) heading `dir` (forward unless ping-ponging) at `now`. */
253
+ anchor(frame, dir, now) {
254
+ this.startNow = now;
255
+ this.startFrame = this.clampToRange(frame);
256
+ this.startDir = this._loopMode === "pingpong" ? dir : 1;
257
+ }
258
+ clampToRange(index) {
259
+ return Math.min(this._rangeEnd, Math.max(this._rangeStart, index));
260
+ }
261
+ /** The frame `steps` after `from` (absolute index) heading `dir`, with the direction there. */
262
+ stepFrom(from, dir, steps) {
263
+ let frame = this.clampToRange(from);
264
+ let d = dir;
265
+ for (let k = 0; k < steps; k++) {
266
+ let next = frame + d;
267
+ if (next > this._rangeEnd || next < this._rangeStart) {
268
+ if (this._loopMode === "once")
269
+ break;
270
+ if (this._loopMode === "pingpong" && this._rangeEnd > this._rangeStart) {
271
+ d = d === 1 ? -1 : 1;
272
+ next = frame + d;
273
+ }
274
+ else {
275
+ next = d === 1 ? this._rangeStart : this._rangeEnd;
276
+ }
277
+ }
278
+ frame = next;
279
+ }
280
+ return { frame, dir: d };
281
+ }
282
+ /**
283
+ * The frame the clock points at `advanced` frames after the anchor, and the direction there.
284
+ *
285
+ * A ping-pong over `len` frames is a cycle of `period = 2 (len - 1)` steps: phase `q` in `[0, len - 1]` is frame
286
+ * `rs + q` on the way out, phase `q` in `(len - 1, period)` is frame `rs + period - q` on the way back. An anchor
287
+ * at offset `o = startFrame - rs` heading forward sits at phase `o`, heading back at phase `period - o` (the two
288
+ * agree at the ends: `o = len - 1` gives `len - 1` either way, `o = 0` gives 0 or `period`, the same phase).
289
+ */
290
+ frameAt(advanced) {
291
+ const rs = this._rangeStart;
292
+ const len = this._rangeEnd - rs + 1;
293
+ const o = this.clampToRange(this.startFrame) - rs;
294
+ if (len === 1)
295
+ return { frame: rs, dir: 1 };
296
+ if (this._loopMode === "once")
297
+ return { frame: rs + Math.min(o + advanced, len - 1), dir: 1 };
298
+ if (this._loopMode === "repeat")
299
+ return { frame: rs + ((o + advanced) % len), dir: 1 };
300
+ const period = 2 * (len - 1);
301
+ const q = ((this.startDir === 1 ? o : period - o) + advanced) % period;
302
+ return { frame: rs + (q < len ? q : period - q), dir: q < len - 1 ? 1 : -1 };
303
+ }
304
+ /**
305
+ * Ensure the frames `[from .. from+prefetch]` in playback order (wrapping or turning around in the range when
306
+ * looping) are decoding or decoded, and evict frames outside that window to bound memory.
307
+ */
308
+ ensurePrefetch(from, dir) {
309
+ const want = new Set();
310
+ const first = this.clampToRange(from);
311
+ for (let k = 0; k <= this.prefetch; k++)
312
+ want.add(this.stepFrom(first, dir, k).frame);
313
+ // Keep the current frame available for hold-last-frame even if it slipped
314
+ // out of the forward window (prefetch 0 edge case).
315
+ if (this._frame >= 0)
316
+ want.add(this._frame);
317
+ for (const index of want)
318
+ this.decodeFrame(index);
319
+ // Evict decoded frames we no longer want ahead of us.
320
+ for (const index of [...this.ring.keys()]) {
321
+ if (!want.has(index))
322
+ this.ring.delete(index);
323
+ }
324
+ }
325
+ /**
326
+ * Start (or return) the decode of one frame; resolves into the ring. A
327
+ * failed frame is not retried (see the file comment); a decode that settles
328
+ * after `dispose()` is dropped.
329
+ */
330
+ decodeFrame(index) {
331
+ if (this.ring.has(index) || this.failed.has(index))
332
+ return Promise.resolve();
333
+ const existing = this.inflight.get(index);
334
+ if (existing)
335
+ return existing;
336
+ const generation = this.generation;
337
+ const current = () => generation === this.generation;
338
+ let load;
339
+ try {
340
+ load = Promise.resolve(this.loader(this.urlFor(index), index));
341
+ }
342
+ catch (err) {
343
+ load = Promise.reject(err);
344
+ }
345
+ const p = load
346
+ .then((image) => {
347
+ if (!current())
348
+ return;
349
+ this.ring.set(index, image);
350
+ if (index === this.pendingFrame && !this.playing)
351
+ this.showFrame(index, this.pendingDir);
352
+ })
353
+ .catch((err) => {
354
+ if (!current())
355
+ return;
356
+ this.failed.add(index);
357
+ this.onError?.(err, index);
358
+ })
359
+ .finally(() => {
360
+ if (current())
361
+ this.inflight.delete(index);
362
+ });
363
+ this.inflight.set(index, p);
364
+ return p;
365
+ }
366
+ assertLive(what) {
367
+ if (this.disposed)
368
+ throw new VDBError("VDB_DISPOSED", `VDBSequence: ${what} after dispose(). Create a new VDBSequence.`);
369
+ }
370
+ decodedAhead() {
371
+ if (this._frame < 0)
372
+ return this.ring.size;
373
+ let count = 0;
374
+ const seen = new Set([this._frame]);
375
+ for (let k = 1; k <= this.prefetch; k++) {
376
+ const next = this.stepFrom(this._frame, this._dir, k).frame;
377
+ if (seen.has(next))
378
+ continue;
379
+ seen.add(next);
380
+ if (this.ring.has(next))
381
+ count++;
382
+ }
383
+ return count;
384
+ }
385
+ /**
386
+ * Decode the first `count` frames of the range (in playback order) and resolve once all are ready. Useful for
387
+ * a deterministic warm start (the demo's `?test=1` awaits this so playback has
388
+ * zero stalls). Does not start playback.
389
+ */
390
+ async preload(count = Math.min(this.frameCount, this.prefetch + 1)) {
391
+ this.assertLive("preload()");
392
+ const n = Math.min(count, this._rangeEnd - this._rangeStart + 1);
393
+ const ps = [];
394
+ for (let i = 0; i < n; i++)
395
+ ps.push(this.decodeFrame(this.stepFrom(this._rangeStart, 1, i).frame));
396
+ await Promise.all(ps);
397
+ }
398
+ /**
399
+ * Begin playback into grid `target.id` of `target.pool`. Replaces it with
400
+ * the first frame of the range (frame 0 by default) at once if that is decoded (else the first `update` that finds it
401
+ * ready does), kicks off prefetch, and anchors the clock at `now` (defaults
402
+ * to the injected clock). Call `update(now)` every animation frame thereafter.
403
+ * Clears the failed set (failed frames are retried).
404
+ *
405
+ * @param target Where frames go: `{ pool, id }` or `{ source }`.
406
+ * @param now Clock time in ms the playback is anchored at (default: the injected clock).
407
+ *
408
+ * @throws VDBError `VDB_DISPOSED` after `dispose()`; `VDB_BAD_OPTION` for a bad target.
409
+ */
410
+ start(target, now = this.now()) {
411
+ this.assertLive("start()");
412
+ const t = target;
413
+ if (t !== null && typeof t === "object" && !("pool" in t) && typeof t.source?.replace === "function") {
414
+ if (!this.hasLoader)
415
+ throw new VDBError("VDB_BAD_OPTION", "VDBSequence.start: a { source } target plays the frames your loader returns; pass a loader (the default decodes .nvdb images).");
416
+ const source = t.source;
417
+ this.replaceFrame = (frame) => source.replace(frame);
418
+ }
419
+ else if (t === null || typeof t !== "object" || typeof t.pool?.replace !== "function" || !Number.isInteger(t.id) || t.id < 0) {
420
+ throw new VDBError("VDB_BAD_OPTION", "VDBSequence.start: target must be { pool, id } with a VDBGridPool (or an object with replace(id, image)) and a non-negative grid id, or { source } with replace(frame).");
421
+ }
422
+ else {
423
+ const { pool, id } = target;
424
+ this.replaceFrame = (frame) => pool.replace(id, frame);
425
+ }
426
+ this.playing = true;
427
+ this._dir = 1;
428
+ this.anchor(this._rangeStart, 1, now);
429
+ this._frame = -1;
430
+ this._stalls = 0;
431
+ this._replaceMs = 0;
432
+ this._swaps = 0;
433
+ this.failed.clear();
434
+ this.ensurePrefetch(this._rangeStart, 1);
435
+ this.showFrame(this._rangeStart, 1, true);
436
+ }
437
+ /**
438
+ * Stop playback. The ring is preserved so `start`/`resume`/`seek` can resume cheaply. A frame the clock made due
439
+ * that is still decoding does not land after `stop()`; a frame asked for by `start`, `seek`, `setRange` or
440
+ * `setLoopMode` (before or after the stop) is shown when its decode lands.
441
+ */
442
+ stop() {
443
+ this.playing = false;
444
+ if (!this.pendingExplicit)
445
+ this.pendingFrame = -1;
446
+ }
447
+ /**
448
+ * Resume after `stop()` WITHOUT resetting to frame 0 or clearing stats:
449
+ * re-anchors the clock at `now` from the currently-shown frame so playback
450
+ * continues from where it paused (a ping-pong in the direction it was going).
451
+ * No-op if `start()` was never called.
452
+ *
453
+ * @throws VDBError `VDB_DISPOSED` after `dispose()`.
454
+ */
455
+ resume(now = this.now()) {
456
+ this.assertLive("resume()");
457
+ if (!this.replaceFrame)
458
+ return;
459
+ this.playing = true;
460
+ this.anchor(this._frame < 0 ? this._rangeStart : this._frame, this._dir, now);
461
+ this.ensurePrefetch(this.startFrame, this.startDir);
462
+ }
463
+ /**
464
+ * Jump to `index` (wrapped into the clip, then clamped into the range), re-anchoring the clock there so playback
465
+ * continues from it (a ping-pong keeps its direction). Clears the failed set (failed frames are retried).
466
+ *
467
+ * @param index The frame to jump to.
468
+ * @param now Clock time in ms to re-anchor at (default: the injected clock).
469
+ *
470
+ * @throws VDBError `VDB_DISPOSED` after `dispose()`.
471
+ */
472
+ seek(index, now = this.now()) {
473
+ this.assertLive("seek()");
474
+ this.failed.clear();
475
+ this.anchor(this.wrap(Math.trunc(index)), this._dir, now);
476
+ this.ensurePrefetch(this.startFrame, this.startDir);
477
+ this.showFrame(this.startFrame, this.startDir, true);
478
+ }
479
+ /**
480
+ * Advance the scheduler to time `now`. Replaces the grid with the frame the
481
+ * clock points at if it is decoded; otherwise holds the last frame and counts
482
+ * a stall. Never blocks. Returns the frame index currently shown.
483
+ */
484
+ update(now) {
485
+ if (!this.playing || !this.replaceFrame)
486
+ return this._frame;
487
+ const elapsed = now - this.startNow;
488
+ const advanced = Math.floor(elapsed / this.frameDurationMs);
489
+ const { frame: target, dir } = this.frameAt(advanced);
490
+ if (target === this._frame) {
491
+ // Same frame is due; just keep prefetch warm.
492
+ this._dir = dir;
493
+ this.pendingFrame = -1;
494
+ this.ensurePrefetch(target, dir);
495
+ return this._frame;
496
+ }
497
+ this.showFrame(target, dir);
498
+ return this._frame;
499
+ }
500
+ /**
501
+ * Show `index` (playback heading `dir` there) if decoded (`pool.replace`, counts a swap, fires `onFrame`,
502
+ * advances prefetch); otherwise count a stall and hold. Shared by start/seek/update.
503
+ */
504
+ showFrame(index, dir, explicit = false) {
505
+ if (!this.replaceFrame)
506
+ return;
507
+ const image = this.ring.get(index);
508
+ if (image === undefined) {
509
+ // Not decoded yet: hold the last frame, count a stall, keep decoding (a stopped player shows an explicit
510
+ // request, start / seek / a range or mode change, when it lands).
511
+ if (this._frame !== index)
512
+ this._stalls++;
513
+ this.pendingFrame = index;
514
+ this.pendingDir = dir;
515
+ this.pendingExplicit = explicit;
516
+ this.ensurePrefetch(index, dir);
517
+ return;
518
+ }
519
+ this.pendingFrame = -1;
520
+ this._dir = dir;
521
+ if (index === this._frame)
522
+ return;
523
+ const t0 = this.now();
524
+ this.replaceFrame(image);
525
+ this._replaceMs = this.now() - t0;
526
+ this._frame = index;
527
+ this._swaps++;
528
+ this.ensurePrefetch(index, dir);
529
+ this.onFrame?.(this.stats);
530
+ }
531
+ /**
532
+ * Stops playback and drops all decoded frames and in-flight tracking; later
533
+ * decodes are dropped when they settle. The pool keeps the grid (and the
534
+ * frame it shows). Further `start` / `seek` / `resume` / `preload` throw
535
+ * `VDB_DISPOSED`. Idempotent.
536
+ */
537
+ dispose() {
538
+ this.disposed = true;
539
+ this.generation++;
540
+ this.playing = false;
541
+ this.replaceFrame = undefined;
542
+ this.pendingFrame = -1;
543
+ this.ring.clear();
544
+ this.inflight.clear();
545
+ this.failed.clear();
546
+ }
547
+ }
548
+ //# sourceMappingURL=sequence.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sequence.js","sourceRoot":"","sources":["../../src/core/sequence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2EG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,QAAQ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AI,CAAC,KAAK,CAAC,CAAC;IAC7B,CAAC;IAED;;;;;OAKG;IACH,OAAO;QACL,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,CAAC,UAAU,EAAE,CAAC;QAClB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACrB,IAAI,CAAC,YAAY,GAAG,SAAS,CAAC;QAC9B,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC;QACvB,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;QAClB,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACtB,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;CACF","sourcesContent":["/**\n * `VDBSequence`: manifest-driven animated-volume playback on a `VDBGridPool`\n * (task K2.3; v1's `NanoVDBSequence`, docs/archive/v1/SPEC.md §3.5). Decodes per-frame grid\n * images ahead of time into a bounded prefetch ring and swaps the shown one\n * into ONE pool id with `pool.replace(id, image)`.\n *\n * ## The pool contract\n *\n * const id = pool.add(firstFrame, { capacity: largestFrameBytes });\n * sequence.start({ pool, id });\n * // every frame:\n * sequence.update(performance.now()); // may call pool.replace(id, frame)\n * pool.update(encoder) / pool.flush(); // writes the frame in place\n * grids.update(); // VDBGridNode: rebinds only after a growth\n * renderer.render(scene, camera);\n *\n * Reserve `capacity` for the largest frame: every `replace` then writes in\n * place (no move, no `pool.version` change, no rebind, no new bind group). A\n * frame larger than the capacity still works, but it moves the image, and the\n * next `update` may grow the pool (a `version` bump), so keep calling\n * `grids.update()` after the pool's update either way.\n *\n * **Frame arrays are held by reference.** `replace` keeps the image until the\n * `update` that writes it, and until `pool.settled()` resolves while a growth\n * is unconfirmed (the pool may have to stage it again after a rollback). The\n * player never writes into a frame array, and its ring only drops references.\n * A custom `loader` that recycles frame buffers must not reuse an array it\n * returned before `await pool.settled()` after the update that wrote it.\n *\n * ## Design for testability (the scheduler is a pure clock consumer)\n *\n * The player never owns the animation loop or reads the wall clock itself.\n * `update(now)` takes the current time in ms; the consumer calls it from its\n * own `requestAnimationFrame` loop with `performance.now()`, and tests call it\n * with a fake, hand-advanced clock. The pool is reached only through\n * `replace(id, image)`, so tests pass a stub.\n *\n * ## Stall policy: never block the render loop\n *\n * If the frame that is due hasn't finished decoding, `update()` does not wait:\n * it holds the last-shown frame, counts a stall, and returns. Decoding\n * continues in the background; the next `update()` that finds the frame ready\n * advances to wherever the clock now points (intermediate frames are dropped:\n * real-time catch-up, not slow motion).\n *\n * ## Frame range and loop mode\n *\n * `range: [start, end]` (inclusive frame indices) limits playback to those frames; the default is all of them.\n * `loopMode: 'repeat'` (default) wraps from `end` to `start`; `'pingpong'` plays forward then backward\n * (`start .. end .. start`), with each end frame shown once per turn (no doubled frame at the ends); `'once'` plays\n * to `end` and holds there. `start()` shows `range[0]`. `seek(i)` wraps `i` into the clip, then clamps it into the\n * range. `setRange()` and `setLoopMode()` change them while playing (playback continues from the shown frame,\n * clamped into the new range). The prefetch ring follows the playback order, so a swap is always a `pool.replace`\n * of a frame the ring already holds.\n *\n * **Direction.** A ping-pong keeps its direction across `stop()` / `resume()`, `seek()` and `setRange()`: paused on\n * the way back, it resumes on the way back. `start()` goes forward; `setLoopMode()` keeps the direction only when the\n * new mode is `'pingpong'` (`'repeat'` and `'once'` only go forward).\n *\n * ## Failed frames: no retry until `seek` / `start`\n *\n * A frame whose loader rejects goes into a failed set: `onError` fires once,\n * and the player does not ask the loader for it again (no retry storm from\n * the per-frame prefetch). While the clock points at it, `update()` holds the\n * last frame and counts stalls; playback moves on when the clock reaches the\n * next decodable frame. `seek()` and `start()` clear the set, so they retry\n * every failed frame (call `seek(stats.frame)` to retry in place).\n * `stats.failed` counts the frames in the set.\n *\n * ## Disposal\n *\n * `dispose()` drops the ring and the in-flight tracking and bumps a\n * generation token: decodes that finish later are dropped (no ring entry, no\n * `onError`). `start`, `seek`, `resume` and `preload` after `dispose()` throw\n * (or reject with) `VDB_DISPOSED`; `update` returns the last frame.\n */\n\nimport { VDBError } from \"./errors.js\";\nimport { NvdbFile } from \"../tools/nvdb-file.js\";\n\n/** The part of a `VDBGridPool` the player uses. */\nexport interface VDBSequencePoolLike<TFrame = Uint32Array> {\n /**\n * Stages a new image for grid `id` (`VDBGridPool.replace`).\n *\n * @param id The grid's pool id.\n * @param image The frame to show.\n */\n replace(id: number, image: TFrame): void;\n}\n\n/**\n * Where frames go: grid `id` of `pool` (added with `capacity` for the largest frame), or (K5.9) a `source` with\n * `replace(frame)`: a dense `.wvdb` source (`vdbDenseTextures`) playing `WvdbDenseVolume` frames, which a\n * `VDBFrameVolume` over it follows by itself.\n */\nexport type VDBSequenceTarget<TFrame = Uint32Array> =\n | { readonly pool: VDBSequencePoolLike<TFrame>; readonly id: number }\n | { readonly source: { replace(frame: TFrame): void } };\n\n/** Decodes one frame's URL (or index) into a frame: a NanoVDB grid image by default. */\nexport type VDBSequenceFrameLoader<TFrame = Uint32Array> = (url: string, index: number) => Promise<TFrame>;\n\n/**\n * What playback does at the end of its range: wrap to the start (`'repeat'`), turn around (`'pingpong'`), or hold\n * the end frame (`'once'`).\n */\nexport type VDBSequenceLoopMode = \"once\" | \"repeat\" | \"pingpong\";\n\nconst LOOP_MODES: readonly VDBSequenceLoopMode[] = [\"once\", \"repeat\", \"pingpong\"];\n\n/** An inclusive `[start, end]` frame range. */\nexport type VDBSequenceRange = readonly [start: number, end: number];\n\n/** Options of {@link VDBSequence}. */\nexport interface VDBSequenceOptions<TFrame = Uint32Array> {\n /** Per-frame source URLs: an array, or `(i) => url`. Length/`frameCount` gate playback. */\n urls: string[] | ((index: number) => string);\n /** Total frame count. Defaults to `urls.length` when `urls` is an array (required otherwise). */\n frameCount?: number;\n /** Playback rate. Default 24. */\n fps?: number;\n /** How many frames to decode ahead of the current one. Default 3. */\n prefetch?: number;\n /**\n * Inclusive `[start, end]` frames to play. Default `[0, frameCount - 1]` (all frames).\n * @throws VDBError `VDB_BAD_OPTION` unless both are integers with `0 <= start <= end < frameCount`.\n */\n range?: VDBSequenceRange;\n /**\n * What playback does at the range end: `'repeat'` (default) wraps to the start; `'pingpong'` plays back to the\n * start and forward again; `'once'` holds the end frame. Change it while playing with `setLoopMode()`.\n * @throws VDBError `VDB_BAD_OPTION` for any other value.\n */\n loopMode?: VDBSequenceLoopMode;\n /**\n * Decode override. Default: `NvdbFile.fromURL(url)` -> `gridImage(0)`.\n * The demo passes an in-memory loader (build frames on the fly, no fetch);\n * the URL/fetch path is exercised via a Blob-URL manifest + this default.\n */\n loader?: VDBSequenceFrameLoader<TFrame>;\n /** Clock source. Default `performance.now`. Injected as a fake in tests. */\n now?: () => number;\n /** Fired whenever a NEW frame is shown (after its `pool.replace`). */\n onFrame?: (stats: Readonly<VDBSequenceStats>) => void;\n /**\n * Fired once when a frame fails to decode. The frame is not retried until\n * `seek` or `start`; playback skips it (a stall while the clock points at it).\n */\n onError?: (error: unknown, index: number) => void;\n}\n\n/** Playback counters read through {@link VDBSequence.stats}. */\nexport interface VDBSequenceStats {\n /** Frame index currently shown. -1 before the first frame binds. */\n frame: number;\n /** Decoded-and-ready frames sitting in the ring ahead of `frame`. */\n decodedAhead: number;\n /** Cumulative count of updates that found the due frame not yet decoded. */\n stalls: number;\n /** CPU time (ms) of the last `pool.replace` (staging only; the GPU write lands in the next pool update). */\n replaceMs: number;\n /** `pool.replace` calls since `start` (the initial frame 0 included). */\n swaps: number;\n /** Frames whose decode failed and that wait for a `seek` / `start` to be retried. */\n failed: number;\n}\n\n/** Default loader: real fetch + parse of grid 0. */\nasync function defaultLoader(url: string): Promise<Uint32Array> {\n const file = await NvdbFile.fromURL(url);\n return file.gridImage(0);\n}\n\n/**\n * Plays a frame sequence into ONE pool grid: decodes frames ahead into a\n * bounded ring and `pool.replace`s the due one, driven by your clock. See the\n * file comment for the pool contract, the stall policy, failed frames and\n * disposal.\n *\n * const id = pool.add(firstFrame, { capacity: largestFrameBytes });\n * const sequence = new VDBSequence({ urls, fps: 24 });\n * sequence.start({ pool, id });\n * // per frame: sequence.update(performance.now()); pool.update(encoder); grids.update(); render\n */\nexport class VDBSequence<TFrame = Uint32Array> {\n /** Total frames of the clip. */\n readonly frameCount: number;\n /** Playback rate in frames per second. */\n readonly fps: number;\n /** How many frames are decoded ahead of the shown one. */\n readonly prefetch: number;\n\n private _rangeStart = 0;\n private _rangeEnd = 0;\n private _loopMode: VDBSequenceLoopMode = \"repeat\";\n /** Playback direction at the shown frame: +1, or -1 on the way back of a ping-pong. */\n private _dir: 1 | -1 = 1;\n /** Direction at the clock anchor (`startFrame`): -1 when it was anchored on the way back of a ping-pong. */\n private startDir: 1 | -1 = 1;\n\n private readonly urlFor: (index: number) => string;\n private readonly loader: VDBSequenceFrameLoader<TFrame>;\n private readonly hasLoader: boolean;\n private readonly now: () => number;\n private readonly onFrame: VDBSequenceOptions<TFrame>[\"onFrame\"];\n private readonly onError: VDBSequenceOptions<TFrame>[\"onError\"];\n private readonly frameDurationMs: number;\n\n /** Decoded frame images by frame index. */\n private readonly ring = new Map<number, TFrame>();\n /** In-flight decode promises by frame index (dedupe + stall detection). */\n private readonly inflight = new Map<number, Promise<void>>();\n /** Frames whose decode failed: not retried until `seek` / `start`. */\n private readonly failed = new Set<number>();\n /** Bumped by `dispose()`: a decode that finishes under an older generation is dropped. */\n private generation = 0;\n private disposed = false;\n\n private replaceFrame: ((frame: TFrame) => void) | undefined;\n /** K5.9: a frame shown by `seek` while stopped once its decode lands. */\n private pendingFrame = -1;\n /** The playback direction at `pendingFrame`. */\n private pendingDir: 1 | -1 = 1;\n /** `pendingFrame` was asked for (start / seek / a range or mode change), not made due by the clock: it survives `stop()`. */\n private pendingExplicit = false;\n private playing = false;\n private startNow = 0;\n private startFrame = 0;\n private _frame = -1;\n private _stalls = 0;\n private _replaceMs = 0;\n private _swaps = 0;\n\n /**\n * Creates the player; nothing is loaded until `start`.\n *\n * @param opts URLs, frame count, rate, prefetch, range, loop mode, loader, clock and callbacks.\n */\n constructor(opts: VDBSequenceOptions<TFrame>) {\n const frameCount = opts.frameCount ?? (Array.isArray(opts.urls) ? opts.urls.length : undefined);\n if (frameCount === undefined || !Number.isInteger(frameCount) || frameCount < 1) {\n throw new VDBError(\n \"VDB_BAD_OPTION\",\n \"VDBSequence: `frameCount` is required (a positive integer) when `urls` is a function; \" +\n \"with an array of urls it defaults to urls.length.\",\n );\n }\n this.frameCount = frameCount;\n this.fps = opts.fps ?? 24;\n if (!(this.fps > 0)) throw new VDBError(\"VDB_BAD_OPTION\", `VDBSequence: fps must be > 0 (got ${this.fps}).`);\n this.prefetch = Math.max(0, opts.prefetch ?? 3);\n this._rangeEnd = frameCount - 1;\n if (opts.range !== undefined) this.checkRange(opts.range, \"VDBSequence\");\n this._loopMode = this.checkLoopMode(opts.loopMode ?? \"repeat\", \"VDBSequence\");\n this.frameDurationMs = 1000 / this.fps;\n\n const urls = opts.urls;\n this.urlFor = typeof urls === \"function\" ? urls : (i: number): string => urls[i] ?? \"\";\n this.hasLoader = !!opts.loader;\n this.loader = opts.loader ?? (defaultLoader as unknown as VDBSequenceFrameLoader<TFrame>);\n this.now = opts.now ?? ((): number => performance.now());\n this.onFrame = opts.onFrame;\n this.onError = opts.onError;\n }\n\n /** A snapshot of the playback counters. */\n get stats(): Readonly<VDBSequenceStats> {\n return {\n frame: this._frame,\n decodedAhead: this.decodedAhead(),\n stalls: this._stalls,\n replaceMs: this._replaceMs,\n swaps: this._swaps,\n failed: this.failed.size,\n };\n }\n\n /** True while the clock is running: after `start` or `resume`, until `stop`. */\n get isPlaying(): boolean {\n return this.playing;\n }\n\n /** Wrap a raw (possibly negative or >= frameCount) index into [0, frameCount). */\n private wrap(index: number): number {\n const n = this.frameCount;\n return ((index % n) + n) % n;\n }\n\n /** The playback range, inclusive: `[0, frameCount - 1]` unless set. */\n get range(): VDBSequenceRange {\n return [this._rangeStart, this._rangeEnd];\n }\n\n /** What playback does at the range end (`'repeat'` unless set). */\n get loopMode(): VDBSequenceLoopMode {\n return this._loopMode;\n }\n\n private checkRange(range: VDBSequenceRange, who: string): void {\n const [a, b] = Array.isArray(range) ? range : [NaN, NaN];\n if (!Number.isInteger(a) || !Number.isInteger(b) || a < 0 || b < a || b >= this.frameCount) {\n throw new VDBError(\n \"VDB_BAD_OPTION\",\n `${who}: range must be [start, end] integers with 0 <= start <= end < frameCount (${this.frameCount}); got ${JSON.stringify(range)}.`,\n );\n }\n this._rangeStart = a;\n this._rangeEnd = b;\n }\n\n private checkLoopMode(mode: unknown, who: string): VDBSequenceLoopMode {\n if (!LOOP_MODES.includes(mode as VDBSequenceLoopMode)) {\n throw new VDBError(\"VDB_BAD_OPTION\", `${who}: loopMode must be 'once', 'repeat' or 'pingpong' (got ${String(mode)}).`);\n }\n return mode as VDBSequenceLoopMode;\n }\n\n /**\n * Change the playback range (inclusive). While playing, playback continues from the shown frame, clamped into the\n * new range (the clock re-anchors there; a ping-pong keeps its direction); the prefetch ring is refilled in the\n * new order.\n *\n * @param range Inclusive `[start, end]` frame range.\n * @param now Clock time in ms to re-anchor at (default: the injected clock).\n *\n * @throws VDBError `VDB_BAD_OPTION` for a bad range; `VDB_DISPOSED` after `dispose()`.\n */\n setRange(range: VDBSequenceRange, now: number = this.now()): void {\n this.assertLive(\"setRange()\");\n this.checkRange(range, \"VDBSequence.setRange\");\n this.reanchor(now);\n }\n\n /**\n * Change what playback does at the range end. Playback continues from the shown frame: going forward, or, when\n * both the old and the new mode are `'pingpong'`, in its current direction. Switching to `'once'` at the range end\n * holds there; switching from `'once'` held at the end to `'repeat'` or `'pingpong'` plays on.\n *\n * @param mode `'once'`, `'repeat'` or `'pingpong'`.\n * @param now Clock time in ms to re-anchor at (default: the injected clock).\n *\n * @throws VDBError `VDB_BAD_OPTION` for an unknown mode; `VDB_DISPOSED` after `dispose()`.\n */\n setLoopMode(mode: VDBSequenceLoopMode, now: number = this.now()): void {\n this.assertLive(\"setLoopMode()\");\n this._loopMode = this.checkLoopMode(mode, \"VDBSequence.setLoopMode\");\n if (this._loopMode !== \"pingpong\") this._dir = 1;\n this.reanchor(now);\n }\n\n /** Re-anchor the clock at the shown frame (clamped into the range) after a range or mode change. */\n private reanchor(now: number): void {\n this.anchor(this._frame < 0 ? this._rangeStart : this._frame, this._dir, now);\n if (!this.replaceFrame) return;\n this.ensurePrefetch(this.startFrame, this.startDir);\n if (this._frame < 0 || this._frame !== this.startFrame) this.showFrame(this.startFrame, this.startDir, true);\n }\n\n /** Anchor the clock at `frame` (clamped into the range) heading `dir` (forward unless ping-ponging) at `now`. */\n private anchor(frame: number, dir: 1 | -1, now: number): void {\n this.startNow = now;\n this.startFrame = this.clampToRange(frame);\n this.startDir = this._loopMode === \"pingpong\" ? dir : 1;\n }\n\n private clampToRange(index: number): number {\n return Math.min(this._rangeEnd, Math.max(this._rangeStart, index));\n }\n\n /** The frame `steps` after `from` (absolute index) heading `dir`, with the direction there. */\n private stepFrom(from: number, dir: 1 | -1, steps: number): { frame: number; dir: 1 | -1 } {\n let frame = this.clampToRange(from);\n let d = dir;\n for (let k = 0; k < steps; k++) {\n let next = frame + d;\n if (next > this._rangeEnd || next < this._rangeStart) {\n if (this._loopMode === \"once\") break;\n if (this._loopMode === \"pingpong\" && this._rangeEnd > this._rangeStart) {\n d = d === 1 ? -1 : 1;\n next = frame + d;\n } else {\n next = d === 1 ? this._rangeStart : this._rangeEnd;\n }\n }\n frame = next;\n }\n return { frame, dir: d };\n }\n\n /**\n * The frame the clock points at `advanced` frames after the anchor, and the direction there.\n *\n * A ping-pong over `len` frames is a cycle of `period = 2 (len - 1)` steps: phase `q` in `[0, len - 1]` is frame\n * `rs + q` on the way out, phase `q` in `(len - 1, period)` is frame `rs + period - q` on the way back. An anchor\n * at offset `o = startFrame - rs` heading forward sits at phase `o`, heading back at phase `period - o` (the two\n * agree at the ends: `o = len - 1` gives `len - 1` either way, `o = 0` gives 0 or `period`, the same phase).\n */\n private frameAt(advanced: number): { frame: number; dir: 1 | -1 } {\n const rs = this._rangeStart;\n const len = this._rangeEnd - rs + 1;\n const o = this.clampToRange(this.startFrame) - rs;\n if (len === 1) return { frame: rs, dir: 1 };\n if (this._loopMode === \"once\") return { frame: rs + Math.min(o + advanced, len - 1), dir: 1 };\n if (this._loopMode === \"repeat\") return { frame: rs + ((o + advanced) % len), dir: 1 };\n const period = 2 * (len - 1);\n const q = ((this.startDir === 1 ? o : period - o) + advanced) % period;\n return { frame: rs + (q < len ? q : period - q), dir: q < len - 1 ? 1 : -1 };\n }\n\n /**\n * Ensure the frames `[from .. from+prefetch]` in playback order (wrapping or turning around in the range when\n * looping) are decoding or decoded, and evict frames outside that window to bound memory.\n */\n private ensurePrefetch(from: number, dir: 1 | -1): void {\n const want = new Set<number>();\n const first = this.clampToRange(from);\n for (let k = 0; k <= this.prefetch; k++) want.add(this.stepFrom(first, dir, k).frame);\n // Keep the current frame available for hold-last-frame even if it slipped\n // out of the forward window (prefetch 0 edge case).\n if (this._frame >= 0) want.add(this._frame);\n\n for (const index of want) this.decodeFrame(index);\n\n // Evict decoded frames we no longer want ahead of us.\n for (const index of [...this.ring.keys()]) {\n if (!want.has(index)) this.ring.delete(index);\n }\n }\n\n /**\n * Start (or return) the decode of one frame; resolves into the ring. A\n * failed frame is not retried (see the file comment); a decode that settles\n * after `dispose()` is dropped.\n */\n private decodeFrame(index: number): Promise<void> {\n if (this.ring.has(index) || this.failed.has(index)) return Promise.resolve();\n const existing = this.inflight.get(index);\n if (existing) return existing;\n\n const generation = this.generation;\n const current = (): boolean => generation === this.generation;\n let load: Promise<TFrame>;\n try {\n load = Promise.resolve(this.loader(this.urlFor(index), index));\n } catch (err) {\n load = Promise.reject(err);\n }\n const p = load\n .then((image) => {\n if (!current()) return;\n this.ring.set(index, image);\n if (index === this.pendingFrame && !this.playing) this.showFrame(index, this.pendingDir);\n })\n .catch((err) => {\n if (!current()) return;\n this.failed.add(index);\n this.onError?.(err, index);\n })\n .finally(() => {\n if (current()) this.inflight.delete(index);\n });\n this.inflight.set(index, p);\n return p;\n }\n\n private assertLive(what: string): void {\n if (this.disposed) throw new VDBError(\"VDB_DISPOSED\", `VDBSequence: ${what} after dispose(). Create a new VDBSequence.`);\n }\n\n private decodedAhead(): number {\n if (this._frame < 0) return this.ring.size;\n let count = 0;\n const seen = new Set<number>([this._frame]);\n for (let k = 1; k <= this.prefetch; k++) {\n const next = this.stepFrom(this._frame, this._dir, k).frame;\n if (seen.has(next)) continue;\n seen.add(next);\n if (this.ring.has(next)) count++;\n }\n return count;\n }\n\n /**\n * Decode the first `count` frames of the range (in playback order) and resolve once all are ready. Useful for\n * a deterministic warm start (the demo's `?test=1` awaits this so playback has\n * zero stalls). Does not start playback.\n */\n async preload(count = Math.min(this.frameCount, this.prefetch + 1)): Promise<void> {\n this.assertLive(\"preload()\");\n const n = Math.min(count, this._rangeEnd - this._rangeStart + 1);\n const ps: Promise<void>[] = [];\n for (let i = 0; i < n; i++) ps.push(this.decodeFrame(this.stepFrom(this._rangeStart, 1, i).frame));\n await Promise.all(ps);\n }\n\n /**\n * Begin playback into grid `target.id` of `target.pool`. Replaces it with\n * the first frame of the range (frame 0 by default) at once if that is decoded (else the first `update` that finds it\n * ready does), kicks off prefetch, and anchors the clock at `now` (defaults\n * to the injected clock). Call `update(now)` every animation frame thereafter.\n * Clears the failed set (failed frames are retried).\n *\n * @param target Where frames go: `{ pool, id }` or `{ source }`.\n * @param now Clock time in ms the playback is anchored at (default: the injected clock).\n *\n * @throws VDBError `VDB_DISPOSED` after `dispose()`; `VDB_BAD_OPTION` for a bad target.\n */\n start(target: VDBSequenceTarget<TFrame>, now: number = this.now()): void {\n this.assertLive(\"start()\");\n const t = target as { pool?: { replace?: unknown }; id?: unknown; source?: { replace?: unknown } } | null;\n if (t !== null && typeof t === \"object\" && !(\"pool\" in t) && typeof t.source?.replace === \"function\") {\n if (!this.hasLoader) throw new VDBError(\"VDB_BAD_OPTION\", \"VDBSequence.start: a { source } target plays the frames your loader returns; pass a loader (the default decodes .nvdb images).\");\n const source = t.source as { replace(frame: TFrame): void };\n this.replaceFrame = (frame) => source.replace(frame);\n } else if (t === null || typeof t !== \"object\" || typeof t.pool?.replace !== \"function\" || !Number.isInteger(t.id) || (t.id as number) < 0) {\n throw new VDBError(\n \"VDB_BAD_OPTION\",\n \"VDBSequence.start: target must be { pool, id } with a VDBGridPool (or an object with replace(id, image)) and a non-negative grid id, or { source } with replace(frame).\");\n } else {\n const { pool, id } = target as { pool: VDBSequencePoolLike<TFrame>; id: number };\n this.replaceFrame = (frame) => pool.replace(id, frame);\n }\n this.playing = true;\n this._dir = 1;\n this.anchor(this._rangeStart, 1, now);\n this._frame = -1;\n this._stalls = 0;\n this._replaceMs = 0;\n this._swaps = 0;\n this.failed.clear();\n this.ensurePrefetch(this._rangeStart, 1);\n this.showFrame(this._rangeStart, 1, true);\n }\n\n /**\n * Stop playback. The ring is preserved so `start`/`resume`/`seek` can resume cheaply. A frame the clock made due\n * that is still decoding does not land after `stop()`; a frame asked for by `start`, `seek`, `setRange` or\n * `setLoopMode` (before or after the stop) is shown when its decode lands.\n */\n stop(): void {\n this.playing = false;\n if (!this.pendingExplicit) this.pendingFrame = -1;\n }\n\n /**\n * Resume after `stop()` WITHOUT resetting to frame 0 or clearing stats:\n * re-anchors the clock at `now` from the currently-shown frame so playback\n * continues from where it paused (a ping-pong in the direction it was going).\n * No-op if `start()` was never called.\n *\n * @throws VDBError `VDB_DISPOSED` after `dispose()`.\n */\n resume(now: number = this.now()): void {\n this.assertLive(\"resume()\");\n if (!this.replaceFrame) return;\n this.playing = true;\n this.anchor(this._frame < 0 ? this._rangeStart : this._frame, this._dir, now);\n this.ensurePrefetch(this.startFrame, this.startDir);\n }\n\n /**\n * Jump to `index` (wrapped into the clip, then clamped into the range), re-anchoring the clock there so playback\n * continues from it (a ping-pong keeps its direction). Clears the failed set (failed frames are retried).\n *\n * @param index The frame to jump to.\n * @param now Clock time in ms to re-anchor at (default: the injected clock).\n *\n * @throws VDBError `VDB_DISPOSED` after `dispose()`.\n */\n seek(index: number, now: number = this.now()): void {\n this.assertLive(\"seek()\");\n this.failed.clear();\n this.anchor(this.wrap(Math.trunc(index)), this._dir, now);\n this.ensurePrefetch(this.startFrame, this.startDir);\n this.showFrame(this.startFrame, this.startDir, true);\n }\n\n /**\n * Advance the scheduler to time `now`. Replaces the grid with the frame the\n * clock points at if it is decoded; otherwise holds the last frame and counts\n * a stall. Never blocks. Returns the frame index currently shown.\n */\n update(now: number): number {\n if (!this.playing || !this.replaceFrame) return this._frame;\n\n const elapsed = now - this.startNow;\n const advanced = Math.floor(elapsed / this.frameDurationMs);\n const { frame: target, dir } = this.frameAt(advanced);\n\n if (target === this._frame) {\n // Same frame is due; just keep prefetch warm.\n this._dir = dir;\n this.pendingFrame = -1;\n this.ensurePrefetch(target, dir);\n return this._frame;\n }\n\n this.showFrame(target, dir);\n return this._frame;\n }\n\n /**\n * Show `index` (playback heading `dir` there) if decoded (`pool.replace`, counts a swap, fires `onFrame`,\n * advances prefetch); otherwise count a stall and hold. Shared by start/seek/update.\n */\n private showFrame(index: number, dir: 1 | -1, explicit = false): void {\n if (!this.replaceFrame) return;\n const image = this.ring.get(index);\n if (image === undefined) {\n // Not decoded yet: hold the last frame, count a stall, keep decoding (a stopped player shows an explicit\n // request, start / seek / a range or mode change, when it lands).\n if (this._frame !== index) this._stalls++;\n this.pendingFrame = index;\n this.pendingDir = dir;\n this.pendingExplicit = explicit;\n this.ensurePrefetch(index, dir);\n return;\n }\n this.pendingFrame = -1;\n this._dir = dir;\n if (index === this._frame) return;\n\n const t0 = this.now();\n this.replaceFrame(image);\n this._replaceMs = this.now() - t0;\n this._frame = index;\n this._swaps++;\n this.ensurePrefetch(index, dir);\n this.onFrame?.(this.stats);\n }\n\n /**\n * Stops playback and drops all decoded frames and in-flight tracking; later\n * decodes are dropped when they settle. The pool keeps the grid (and the\n * frame it shows). Further `start` / `seek` / `resume` / `preload` throw\n * `VDB_DISPOSED`. Idempotent.\n */\n dispose(): void {\n this.disposed = true;\n this.generation++;\n this.playing = false;\n this.replaceFrame = undefined;\n this.pendingFrame = -1;\n this.ring.clear();\n this.inflight.clear();\n this.failed.clear();\n }\n}\n"]}