@vfx-js/effects 1.4.4 → 1.5.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 (511) hide show
  1. package/README.md +4 -0
  2. package/THIRD_PARTY_NOTICES.md +61 -0
  3. package/lib/cjs/_bloom-common.d.ts +31 -0
  4. package/lib/cjs/_bloom-common.js +101 -0
  5. package/lib/cjs/_bloom-common.js.map +1 -0
  6. package/lib/cjs/_bubble-fill.d.ts +126 -0
  7. package/lib/cjs/_bubble-fill.js +1044 -0
  8. package/lib/cjs/_bubble-fill.js.map +1 -0
  9. package/lib/cjs/_bubble-kernel-source.d.ts +2 -0
  10. package/lib/cjs/_bubble-kernel-source.js +8 -0
  11. package/lib/cjs/_bubble-kernel-source.js.map +1 -0
  12. package/lib/cjs/_holo/data/kernels.d.ts +4 -0
  13. package/lib/cjs/_holo/data/kernels.js +10 -0
  14. package/lib/cjs/_holo/data/kernels.js.map +1 -0
  15. package/lib/cjs/_holo/data/looks.d.ts +2 -0
  16. package/lib/cjs/_holo/data/looks.js +595 -0
  17. package/lib/cjs/_holo/data/looks.js.map +1 -0
  18. package/lib/cjs/_holo/data/ltc.d.ts +2 -0
  19. package/lib/cjs/_holo/data/ltc.js +11 -0
  20. package/lib/cjs/_holo/data/ltc.js.map +1 -0
  21. package/lib/cjs/_holo/data/material-presets.d.ts +3 -0
  22. package/lib/cjs/_holo/data/material-presets.js +75 -0
  23. package/lib/cjs/_holo/data/material-presets.js.map +1 -0
  24. package/lib/cjs/_holo/data/not-ported.d.ts +5 -0
  25. package/lib/cjs/_holo/data/not-ported.js +190 -0
  26. package/lib/cjs/_holo/data/not-ported.js.map +1 -0
  27. package/lib/cjs/_holo/data/params.d.ts +4 -0
  28. package/lib/cjs/_holo/data/params.js +1641 -0
  29. package/lib/cjs/_holo/data/params.js.map +1 -0
  30. package/lib/cjs/_holo/data/starting-points.d.ts +199 -0
  31. package/lib/cjs/_holo/data/starting-points.js +193 -0
  32. package/lib/cjs/_holo/data/starting-points.js.map +1 -0
  33. package/lib/cjs/_holo/data/studio-presets.d.ts +2 -0
  34. package/lib/cjs/_holo/data/studio-presets.js +177 -0
  35. package/lib/cjs/_holo/data/studio-presets.js.map +1 -0
  36. package/lib/cjs/_holo/emboss-assets.d.ts +55 -0
  37. package/lib/cjs/_holo/emboss-assets.js +155 -0
  38. package/lib/cjs/_holo/emboss-assets.js.map +1 -0
  39. package/lib/cjs/_holo/glare.d.ts +15 -0
  40. package/lib/cjs/_holo/glare.js +125 -0
  41. package/lib/cjs/_holo/glare.js.map +1 -0
  42. package/lib/cjs/_holo/glsl/coat.d.ts +2 -0
  43. package/lib/cjs/_holo/glsl/coat.js +32 -0
  44. package/lib/cjs/_holo/glsl/coat.js.map +1 -0
  45. package/lib/cjs/_holo/glsl/common.d.ts +2 -0
  46. package/lib/cjs/_holo/glsl/common.js +141 -0
  47. package/lib/cjs/_holo/glsl/common.js.map +1 -0
  48. package/lib/cjs/_holo/glsl/emboss.d.ts +2 -0
  49. package/lib/cjs/_holo/glsl/emboss.js +246 -0
  50. package/lib/cjs/_holo/glsl/emboss.js.map +1 -0
  51. package/lib/cjs/_holo/glsl/env.d.ts +2 -0
  52. package/lib/cjs/_holo/glsl/env.js +52 -0
  53. package/lib/cjs/_holo/glsl/env.js.map +1 -0
  54. package/lib/cjs/_holo/glsl/glare-down.d.ts +2 -0
  55. package/lib/cjs/_holo/glsl/glare-down.js +65 -0
  56. package/lib/cjs/_holo/glsl/glare-down.js.map +1 -0
  57. package/lib/cjs/_holo/glsl/glare-up.d.ts +2 -0
  58. package/lib/cjs/_holo/glsl/glare-up.js +18 -0
  59. package/lib/cjs/_holo/glsl/glare-up.js.map +1 -0
  60. package/lib/cjs/_holo/glsl/glitter.d.ts +2 -0
  61. package/lib/cjs/_holo/glsl/glitter.js +325 -0
  62. package/lib/cjs/_holo/glsl/glitter.js.map +1 -0
  63. package/lib/cjs/_holo/glsl/grating.d.ts +2 -0
  64. package/lib/cjs/_holo/glsl/grating.js +240 -0
  65. package/lib/cjs/_holo/glsl/grating.js.map +1 -0
  66. package/lib/cjs/_holo/glsl/holo-emboss.d.ts +2 -0
  67. package/lib/cjs/_holo/glsl/holo-emboss.js +296 -0
  68. package/lib/cjs/_holo/glsl/holo-emboss.js.map +1 -0
  69. package/lib/cjs/_holo/glsl/holo-nebula.d.ts +2 -0
  70. package/lib/cjs/_holo/glsl/holo-nebula.js +186 -0
  71. package/lib/cjs/_holo/glsl/holo-nebula.js.map +1 -0
  72. package/lib/cjs/_holo/glsl/holo-prism.d.ts +2 -0
  73. package/lib/cjs/_holo/glsl/holo-prism.js +183 -0
  74. package/lib/cjs/_holo/glsl/holo-prism.js.map +1 -0
  75. package/lib/cjs/_holo/glsl/holo-shatter.d.ts +2 -0
  76. package/lib/cjs/_holo/glsl/holo-shatter.js +328 -0
  77. package/lib/cjs/_holo/glsl/holo-shatter.js.map +1 -0
  78. package/lib/cjs/_holo/glsl/holo-sparkle.d.ts +2 -0
  79. package/lib/cjs/_holo/glsl/holo-sparkle.js +235 -0
  80. package/lib/cjs/_holo/glsl/holo-sparkle.js.map +1 -0
  81. package/lib/cjs/_holo/glsl/holo-vortex.d.ts +2 -0
  82. package/lib/cjs/_holo/glsl/holo-vortex.js +201 -0
  83. package/lib/cjs/_holo/glsl/holo-vortex.js.map +1 -0
  84. package/lib/cjs/_holo/glsl/ibl.d.ts +2 -0
  85. package/lib/cjs/_holo/glsl/ibl.js +79 -0
  86. package/lib/cjs/_holo/glsl/ibl.js.map +1 -0
  87. package/lib/cjs/_holo/glsl/lights.d.ts +2 -0
  88. package/lib/cjs/_holo/glsl/lights.js +125 -0
  89. package/lib/cjs/_holo/glsl/lights.js.map +1 -0
  90. package/lib/cjs/_holo/glsl/ltc.d.ts +2 -0
  91. package/lib/cjs/_holo/glsl/ltc.js +66 -0
  92. package/lib/cjs/_holo/glsl/ltc.js.map +1 -0
  93. package/lib/cjs/_holo/glsl/output.d.ts +2 -0
  94. package/lib/cjs/_holo/glsl/output.js +113 -0
  95. package/lib/cjs/_holo/glsl/output.js.map +1 -0
  96. package/lib/cjs/_holo/glsl/paper.d.ts +2 -0
  97. package/lib/cjs/_holo/glsl/paper.js +165 -0
  98. package/lib/cjs/_holo/glsl/paper.js.map +1 -0
  99. package/lib/cjs/_holo/glsl/relief.d.ts +2 -0
  100. package/lib/cjs/_holo/glsl/relief.js +103 -0
  101. package/lib/cjs/_holo/glsl/relief.js.map +1 -0
  102. package/lib/cjs/_holo/glsl/sparkle.d.ts +2 -0
  103. package/lib/cjs/_holo/glsl/sparkle.js +279 -0
  104. package/lib/cjs/_holo/glsl/sparkle.js.map +1 -0
  105. package/lib/cjs/_holo/glsl/spectral.d.ts +2 -0
  106. package/lib/cjs/_holo/glsl/spectral.js +60 -0
  107. package/lib/cjs/_holo/glsl/spectral.js.map +1 -0
  108. package/lib/cjs/_holo/glsl/wear.d.ts +2 -0
  109. package/lib/cjs/_holo/glsl/wear.js +107 -0
  110. package/lib/cjs/_holo/glsl/wear.js.map +1 -0
  111. package/lib/cjs/_holo/ltc.d.ts +9 -0
  112. package/lib/cjs/_holo/ltc.js +56 -0
  113. package/lib/cjs/_holo/ltc.js.map +1 -0
  114. package/lib/cjs/_holo/materials/build.d.ts +32 -0
  115. package/lib/cjs/_holo/materials/build.js +36 -0
  116. package/lib/cjs/_holo/materials/build.js.map +1 -0
  117. package/lib/cjs/_holo/materials/emboss.d.ts +22 -0
  118. package/lib/cjs/_holo/materials/emboss.js +205 -0
  119. package/lib/cjs/_holo/materials/emboss.js.map +1 -0
  120. package/lib/cjs/_holo/materials/nebula.d.ts +4 -0
  121. package/lib/cjs/_holo/materials/nebula.js +105 -0
  122. package/lib/cjs/_holo/materials/nebula.js.map +1 -0
  123. package/lib/cjs/_holo/materials/prism.d.ts +2 -0
  124. package/lib/cjs/_holo/materials/prism.js +69 -0
  125. package/lib/cjs/_holo/materials/prism.js.map +1 -0
  126. package/lib/cjs/_holo/materials/registry.d.ts +11 -0
  127. package/lib/cjs/_holo/materials/registry.js +88 -0
  128. package/lib/cjs/_holo/materials/registry.js.map +1 -0
  129. package/lib/cjs/_holo/materials/shatter.d.ts +2 -0
  130. package/lib/cjs/_holo/materials/shatter.js +80 -0
  131. package/lib/cjs/_holo/materials/shatter.js.map +1 -0
  132. package/lib/cjs/_holo/materials/sparkle.d.ts +2 -0
  133. package/lib/cjs/_holo/materials/sparkle.js +108 -0
  134. package/lib/cjs/_holo/materials/sparkle.js.map +1 -0
  135. package/lib/cjs/_holo/materials/vortex.d.ts +2 -0
  136. package/lib/cjs/_holo/materials/vortex.js +85 -0
  137. package/lib/cjs/_holo/materials/vortex.js.map +1 -0
  138. package/lib/cjs/_holo/physics/emboss.d.ts +39 -0
  139. package/lib/cjs/_holo/physics/emboss.js +95 -0
  140. package/lib/cjs/_holo/physics/emboss.js.map +1 -0
  141. package/lib/cjs/_holo/physics/geometry.d.ts +109 -0
  142. package/lib/cjs/_holo/physics/geometry.js +252 -0
  143. package/lib/cjs/_holo/physics/geometry.js.map +1 -0
  144. package/lib/cjs/_holo/physics/grating.d.ts +86 -0
  145. package/lib/cjs/_holo/physics/grating.js +328 -0
  146. package/lib/cjs/_holo/physics/grating.js.map +1 -0
  147. package/lib/cjs/_holo/physics/sparkle.d.ts +143 -0
  148. package/lib/cjs/_holo/physics/sparkle.js +388 -0
  149. package/lib/cjs/_holo/physics/sparkle.js.map +1 -0
  150. package/lib/cjs/_holo/scene/env.d.ts +17 -0
  151. package/lib/cjs/_holo/scene/env.js +151 -0
  152. package/lib/cjs/_holo/scene/env.js.map +1 -0
  153. package/lib/cjs/_holo/scene/lights.d.ts +13 -0
  154. package/lib/cjs/_holo/scene/lights.js +211 -0
  155. package/lib/cjs/_holo/scene/lights.js.map +1 -0
  156. package/lib/cjs/_holo/scene/logo.d.ts +87 -0
  157. package/lib/cjs/_holo/scene/logo.js +655 -0
  158. package/lib/cjs/_holo/scene/logo.js.map +1 -0
  159. package/lib/cjs/_holo/scene/paper-maps.d.ts +26 -0
  160. package/lib/cjs/_holo/scene/paper-maps.js +391 -0
  161. package/lib/cjs/_holo/scene/paper-maps.js.map +1 -0
  162. package/lib/cjs/_holo/scene/pose.d.ts +31 -0
  163. package/lib/cjs/_holo/scene/pose.js +77 -0
  164. package/lib/cjs/_holo/scene/pose.js.map +1 -0
  165. package/lib/cjs/_holo/scene/relief.d.ts +24 -0
  166. package/lib/cjs/_holo/scene/relief.js +148 -0
  167. package/lib/cjs/_holo/scene/relief.js.map +1 -0
  168. package/lib/cjs/_holo/settings-types.d.ts +20 -0
  169. package/lib/cjs/_holo/settings-types.js +3 -0
  170. package/lib/cjs/_holo/settings-types.js.map +1 -0
  171. package/lib/cjs/_holo/settings.d.ts +83 -0
  172. package/lib/cjs/_holo/settings.js +375 -0
  173. package/lib/cjs/_holo/settings.js.map +1 -0
  174. package/lib/cjs/_holo/shader.d.ts +23 -0
  175. package/lib/cjs/_holo/shader.js +219 -0
  176. package/lib/cjs/_holo/shader.js.map +1 -0
  177. package/lib/cjs/_holo/spectral/atlas.d.ts +36 -0
  178. package/lib/cjs/_holo/spectral/atlas.js +114 -0
  179. package/lib/cjs/_holo/spectral/atlas.js.map +1 -0
  180. package/lib/cjs/_holo/spectral/cmf.d.ts +67 -0
  181. package/lib/cjs/_holo/spectral/cmf.js +244 -0
  182. package/lib/cjs/_holo/spectral/cmf.js.map +1 -0
  183. package/lib/cjs/_holo/spectral/float24.d.ts +8 -0
  184. package/lib/cjs/_holo/spectral/float24.js +70 -0
  185. package/lib/cjs/_holo/spectral/float24.js.map +1 -0
  186. package/lib/cjs/_holo/spectral/spd.d.ts +22 -0
  187. package/lib/cjs/_holo/spectral/spd.js +139 -0
  188. package/lib/cjs/_holo/spectral/spd.js.map +1 -0
  189. package/lib/cjs/_holo/spectral/tables.d.ts +62 -0
  190. package/lib/cjs/_holo/spectral/tables.js +386 -0
  191. package/lib/cjs/_holo/spectral/tables.js.map +1 -0
  192. package/lib/cjs/_holo/tier.d.ts +4 -0
  193. package/lib/cjs/_holo/tier.js +110 -0
  194. package/lib/cjs/_holo/tier.js.map +1 -0
  195. package/lib/cjs/_holo/types.d.ts +148 -0
  196. package/lib/cjs/_holo/types.js +14 -0
  197. package/lib/cjs/_holo/types.js.map +1 -0
  198. package/lib/cjs/_kernel-worker.d.ts +22 -0
  199. package/lib/cjs/_kernel-worker.js +174 -0
  200. package/lib/cjs/_kernel-worker.js.map +1 -0
  201. package/lib/cjs/_orbit-camera.d.ts +175 -0
  202. package/lib/cjs/_orbit-camera.js +366 -0
  203. package/lib/cjs/_orbit-camera.js.map +1 -0
  204. package/lib/cjs/_pad.d.ts +2 -0
  205. package/lib/cjs/_pad.js +11 -0
  206. package/lib/cjs/_pad.js.map +1 -1
  207. package/lib/cjs/_scene3d.d.ts +101 -0
  208. package/lib/cjs/_scene3d.js +794 -0
  209. package/lib/cjs/_scene3d.js.map +1 -0
  210. package/lib/cjs/_shape-kernel-source.d.ts +2 -0
  211. package/lib/cjs/_shape-kernel-source.js +8 -0
  212. package/lib/cjs/_shape-kernel-source.js.map +1 -0
  213. package/lib/cjs/_shape-worker.d.ts +8 -0
  214. package/lib/cjs/_shape-worker.js +27 -0
  215. package/lib/cjs/_shape-worker.js.map +1 -0
  216. package/lib/cjs/_silhouette.d.ts +88 -0
  217. package/lib/cjs/_silhouette.js +441 -0
  218. package/lib/cjs/_silhouette.js.map +1 -0
  219. package/lib/cjs/_simplex3.d.ts +2 -0
  220. package/lib/cjs/_simplex3.js +160 -0
  221. package/lib/cjs/_simplex3.js.map +1 -0
  222. package/lib/cjs/_source.d.ts +80 -0
  223. package/lib/cjs/_source.js +192 -0
  224. package/lib/cjs/_source.js.map +1 -0
  225. package/lib/cjs/_sphere-foam.d.ts +34 -0
  226. package/lib/cjs/_sphere-foam.js +135 -0
  227. package/lib/cjs/_sphere-foam.js.map +1 -0
  228. package/lib/cjs/_thin-film.d.ts +26 -0
  229. package/lib/cjs/_thin-film.js +146 -0
  230. package/lib/cjs/_thin-film.js.map +1 -0
  231. package/lib/cjs/bloom.js +40 -106
  232. package/lib/cjs/bloom.js.map +1 -1
  233. package/lib/cjs/bubble.d.ts +284 -0
  234. package/lib/cjs/bubble.js +1820 -0
  235. package/lib/cjs/bubble.js.map +1 -0
  236. package/lib/cjs/glass.d.ts +254 -0
  237. package/lib/cjs/glass.js +981 -0
  238. package/lib/cjs/glass.js.map +1 -0
  239. package/lib/cjs/holo-static.d.ts +3 -0
  240. package/lib/cjs/holo-static.js +29 -0
  241. package/lib/cjs/holo-static.js.map +1 -0
  242. package/lib/cjs/holo.d.ts +401 -0
  243. package/lib/cjs/holo.js +1613 -0
  244. package/lib/cjs/holo.js.map +1 -0
  245. package/lib/cjs/index.d.ts +18 -9
  246. package/lib/cjs/index.js +12 -1
  247. package/lib/cjs/index.js.map +1 -1
  248. package/lib/cjs/jpeg-glitch.js +32 -29
  249. package/lib/cjs/jpeg-glitch.js.map +1 -1
  250. package/lib/cjs/matrix.d.ts +1 -1
  251. package/lib/cjs/package.json +20 -5
  252. package/lib/cjs/swirl-particle.d.ts +257 -0
  253. package/lib/cjs/swirl-particle.js +2346 -0
  254. package/lib/cjs/swirl-particle.js.map +1 -0
  255. package/lib/cjs/voronoi.js +2 -75
  256. package/lib/cjs/voronoi.js.map +1 -1
  257. package/lib/esm/_bloom-common.d.ts +31 -0
  258. package/lib/esm/_bloom-common.js +95 -0
  259. package/lib/esm/_bloom-common.js.map +1 -0
  260. package/lib/esm/_bubble-fill.d.ts +126 -0
  261. package/lib/esm/_bubble-fill.js +1039 -0
  262. package/lib/esm/_bubble-fill.js.map +1 -0
  263. package/lib/esm/_bubble-kernel-source.d.ts +2 -0
  264. package/lib/esm/_bubble-kernel-source.js +5 -0
  265. package/lib/esm/_bubble-kernel-source.js.map +1 -0
  266. package/lib/esm/_holo/data/kernels.d.ts +4 -0
  267. package/lib/esm/_holo/data/kernels.js +7 -0
  268. package/lib/esm/_holo/data/kernels.js.map +1 -0
  269. package/lib/esm/_holo/data/looks.d.ts +2 -0
  270. package/lib/esm/_holo/data/looks.js +592 -0
  271. package/lib/esm/_holo/data/looks.js.map +1 -0
  272. package/lib/esm/_holo/data/ltc.d.ts +2 -0
  273. package/lib/esm/_holo/data/ltc.js +8 -0
  274. package/lib/esm/_holo/data/ltc.js.map +1 -0
  275. package/lib/esm/_holo/data/material-presets.d.ts +3 -0
  276. package/lib/esm/_holo/data/material-presets.js +72 -0
  277. package/lib/esm/_holo/data/material-presets.js.map +1 -0
  278. package/lib/esm/_holo/data/not-ported.d.ts +5 -0
  279. package/lib/esm/_holo/data/not-ported.js +187 -0
  280. package/lib/esm/_holo/data/not-ported.js.map +1 -0
  281. package/lib/esm/_holo/data/params.d.ts +4 -0
  282. package/lib/esm/_holo/data/params.js +1638 -0
  283. package/lib/esm/_holo/data/params.js.map +1 -0
  284. package/lib/esm/_holo/data/starting-points.d.ts +199 -0
  285. package/lib/esm/_holo/data/starting-points.js +190 -0
  286. package/lib/esm/_holo/data/starting-points.js.map +1 -0
  287. package/lib/esm/_holo/data/studio-presets.d.ts +2 -0
  288. package/lib/esm/_holo/data/studio-presets.js +174 -0
  289. package/lib/esm/_holo/data/studio-presets.js.map +1 -0
  290. package/lib/esm/_holo/emboss-assets.d.ts +55 -0
  291. package/lib/esm/_holo/emboss-assets.js +150 -0
  292. package/lib/esm/_holo/emboss-assets.js.map +1 -0
  293. package/lib/esm/_holo/glare.d.ts +15 -0
  294. package/lib/esm/_holo/glare.js +117 -0
  295. package/lib/esm/_holo/glare.js.map +1 -0
  296. package/lib/esm/_holo/glsl/coat.d.ts +2 -0
  297. package/lib/esm/_holo/glsl/coat.js +30 -0
  298. package/lib/esm/_holo/glsl/coat.js.map +1 -0
  299. package/lib/esm/_holo/glsl/common.d.ts +2 -0
  300. package/lib/esm/_holo/glsl/common.js +139 -0
  301. package/lib/esm/_holo/glsl/common.js.map +1 -0
  302. package/lib/esm/_holo/glsl/emboss.d.ts +2 -0
  303. package/lib/esm/_holo/glsl/emboss.js +244 -0
  304. package/lib/esm/_holo/glsl/emboss.js.map +1 -0
  305. package/lib/esm/_holo/glsl/env.d.ts +2 -0
  306. package/lib/esm/_holo/glsl/env.js +50 -0
  307. package/lib/esm/_holo/glsl/env.js.map +1 -0
  308. package/lib/esm/_holo/glsl/glare-down.d.ts +2 -0
  309. package/lib/esm/_holo/glsl/glare-down.js +63 -0
  310. package/lib/esm/_holo/glsl/glare-down.js.map +1 -0
  311. package/lib/esm/_holo/glsl/glare-up.d.ts +2 -0
  312. package/lib/esm/_holo/glsl/glare-up.js +16 -0
  313. package/lib/esm/_holo/glsl/glare-up.js.map +1 -0
  314. package/lib/esm/_holo/glsl/glitter.d.ts +2 -0
  315. package/lib/esm/_holo/glsl/glitter.js +323 -0
  316. package/lib/esm/_holo/glsl/glitter.js.map +1 -0
  317. package/lib/esm/_holo/glsl/grating.d.ts +2 -0
  318. package/lib/esm/_holo/glsl/grating.js +238 -0
  319. package/lib/esm/_holo/glsl/grating.js.map +1 -0
  320. package/lib/esm/_holo/glsl/holo-emboss.d.ts +2 -0
  321. package/lib/esm/_holo/glsl/holo-emboss.js +294 -0
  322. package/lib/esm/_holo/glsl/holo-emboss.js.map +1 -0
  323. package/lib/esm/_holo/glsl/holo-nebula.d.ts +2 -0
  324. package/lib/esm/_holo/glsl/holo-nebula.js +184 -0
  325. package/lib/esm/_holo/glsl/holo-nebula.js.map +1 -0
  326. package/lib/esm/_holo/glsl/holo-prism.d.ts +2 -0
  327. package/lib/esm/_holo/glsl/holo-prism.js +181 -0
  328. package/lib/esm/_holo/glsl/holo-prism.js.map +1 -0
  329. package/lib/esm/_holo/glsl/holo-shatter.d.ts +2 -0
  330. package/lib/esm/_holo/glsl/holo-shatter.js +326 -0
  331. package/lib/esm/_holo/glsl/holo-shatter.js.map +1 -0
  332. package/lib/esm/_holo/glsl/holo-sparkle.d.ts +2 -0
  333. package/lib/esm/_holo/glsl/holo-sparkle.js +233 -0
  334. package/lib/esm/_holo/glsl/holo-sparkle.js.map +1 -0
  335. package/lib/esm/_holo/glsl/holo-vortex.d.ts +2 -0
  336. package/lib/esm/_holo/glsl/holo-vortex.js +199 -0
  337. package/lib/esm/_holo/glsl/holo-vortex.js.map +1 -0
  338. package/lib/esm/_holo/glsl/ibl.d.ts +2 -0
  339. package/lib/esm/_holo/glsl/ibl.js +77 -0
  340. package/lib/esm/_holo/glsl/ibl.js.map +1 -0
  341. package/lib/esm/_holo/glsl/lights.d.ts +2 -0
  342. package/lib/esm/_holo/glsl/lights.js +123 -0
  343. package/lib/esm/_holo/glsl/lights.js.map +1 -0
  344. package/lib/esm/_holo/glsl/ltc.d.ts +2 -0
  345. package/lib/esm/_holo/glsl/ltc.js +64 -0
  346. package/lib/esm/_holo/glsl/ltc.js.map +1 -0
  347. package/lib/esm/_holo/glsl/output.d.ts +2 -0
  348. package/lib/esm/_holo/glsl/output.js +111 -0
  349. package/lib/esm/_holo/glsl/output.js.map +1 -0
  350. package/lib/esm/_holo/glsl/paper.d.ts +2 -0
  351. package/lib/esm/_holo/glsl/paper.js +163 -0
  352. package/lib/esm/_holo/glsl/paper.js.map +1 -0
  353. package/lib/esm/_holo/glsl/relief.d.ts +2 -0
  354. package/lib/esm/_holo/glsl/relief.js +101 -0
  355. package/lib/esm/_holo/glsl/relief.js.map +1 -0
  356. package/lib/esm/_holo/glsl/sparkle.d.ts +2 -0
  357. package/lib/esm/_holo/glsl/sparkle.js +277 -0
  358. package/lib/esm/_holo/glsl/sparkle.js.map +1 -0
  359. package/lib/esm/_holo/glsl/spectral.d.ts +2 -0
  360. package/lib/esm/_holo/glsl/spectral.js +58 -0
  361. package/lib/esm/_holo/glsl/spectral.js.map +1 -0
  362. package/lib/esm/_holo/glsl/wear.d.ts +2 -0
  363. package/lib/esm/_holo/glsl/wear.js +105 -0
  364. package/lib/esm/_holo/glsl/wear.js.map +1 -0
  365. package/lib/esm/_holo/ltc.d.ts +9 -0
  366. package/lib/esm/_holo/ltc.js +52 -0
  367. package/lib/esm/_holo/ltc.js.map +1 -0
  368. package/lib/esm/_holo/materials/build.d.ts +32 -0
  369. package/lib/esm/_holo/materials/build.js +30 -0
  370. package/lib/esm/_holo/materials/build.js.map +1 -0
  371. package/lib/esm/_holo/materials/emboss.d.ts +22 -0
  372. package/lib/esm/_holo/materials/emboss.js +198 -0
  373. package/lib/esm/_holo/materials/emboss.js.map +1 -0
  374. package/lib/esm/_holo/materials/nebula.d.ts +4 -0
  375. package/lib/esm/_holo/materials/nebula.js +98 -0
  376. package/lib/esm/_holo/materials/nebula.js.map +1 -0
  377. package/lib/esm/_holo/materials/prism.d.ts +2 -0
  378. package/lib/esm/_holo/materials/prism.js +63 -0
  379. package/lib/esm/_holo/materials/prism.js.map +1 -0
  380. package/lib/esm/_holo/materials/registry.d.ts +11 -0
  381. package/lib/esm/_holo/materials/registry.js +48 -0
  382. package/lib/esm/_holo/materials/registry.js.map +1 -0
  383. package/lib/esm/_holo/materials/shatter.d.ts +2 -0
  384. package/lib/esm/_holo/materials/shatter.js +74 -0
  385. package/lib/esm/_holo/materials/shatter.js.map +1 -0
  386. package/lib/esm/_holo/materials/sparkle.d.ts +2 -0
  387. package/lib/esm/_holo/materials/sparkle.js +102 -0
  388. package/lib/esm/_holo/materials/sparkle.js.map +1 -0
  389. package/lib/esm/_holo/materials/vortex.d.ts +2 -0
  390. package/lib/esm/_holo/materials/vortex.js +79 -0
  391. package/lib/esm/_holo/materials/vortex.js.map +1 -0
  392. package/lib/esm/_holo/physics/emboss.d.ts +39 -0
  393. package/lib/esm/_holo/physics/emboss.js +89 -0
  394. package/lib/esm/_holo/physics/emboss.js.map +1 -0
  395. package/lib/esm/_holo/physics/geometry.d.ts +109 -0
  396. package/lib/esm/_holo/physics/geometry.js +228 -0
  397. package/lib/esm/_holo/physics/geometry.js.map +1 -0
  398. package/lib/esm/_holo/physics/grating.d.ts +86 -0
  399. package/lib/esm/_holo/physics/grating.js +313 -0
  400. package/lib/esm/_holo/physics/grating.js.map +1 -0
  401. package/lib/esm/_holo/physics/sparkle.d.ts +143 -0
  402. package/lib/esm/_holo/physics/sparkle.js +360 -0
  403. package/lib/esm/_holo/physics/sparkle.js.map +1 -0
  404. package/lib/esm/_holo/scene/env.d.ts +17 -0
  405. package/lib/esm/_holo/scene/env.js +141 -0
  406. package/lib/esm/_holo/scene/env.js.map +1 -0
  407. package/lib/esm/_holo/scene/lights.d.ts +13 -0
  408. package/lib/esm/_holo/scene/lights.js +204 -0
  409. package/lib/esm/_holo/scene/lights.js.map +1 -0
  410. package/lib/esm/_holo/scene/logo.d.ts +87 -0
  411. package/lib/esm/_holo/scene/logo.js +645 -0
  412. package/lib/esm/_holo/scene/logo.js.map +1 -0
  413. package/lib/esm/_holo/scene/paper-maps.d.ts +26 -0
  414. package/lib/esm/_holo/scene/paper-maps.js +387 -0
  415. package/lib/esm/_holo/scene/paper-maps.js.map +1 -0
  416. package/lib/esm/_holo/scene/pose.d.ts +31 -0
  417. package/lib/esm/_holo/scene/pose.js +71 -0
  418. package/lib/esm/_holo/scene/pose.js.map +1 -0
  419. package/lib/esm/_holo/scene/relief.d.ts +24 -0
  420. package/lib/esm/_holo/scene/relief.js +142 -0
  421. package/lib/esm/_holo/scene/relief.js.map +1 -0
  422. package/lib/esm/_holo/settings-types.d.ts +20 -0
  423. package/lib/esm/_holo/settings-types.js +2 -0
  424. package/lib/esm/_holo/settings-types.js.map +1 -0
  425. package/lib/esm/_holo/settings.d.ts +83 -0
  426. package/lib/esm/_holo/settings.js +358 -0
  427. package/lib/esm/_holo/settings.js.map +1 -0
  428. package/lib/esm/_holo/shader.d.ts +23 -0
  429. package/lib/esm/_holo/shader.js +211 -0
  430. package/lib/esm/_holo/shader.js.map +1 -0
  431. package/lib/esm/_holo/spectral/atlas.d.ts +36 -0
  432. package/lib/esm/_holo/spectral/atlas.js +110 -0
  433. package/lib/esm/_holo/spectral/atlas.js.map +1 -0
  434. package/lib/esm/_holo/spectral/cmf.d.ts +67 -0
  435. package/lib/esm/_holo/spectral/cmf.js +230 -0
  436. package/lib/esm/_holo/spectral/cmf.js.map +1 -0
  437. package/lib/esm/_holo/spectral/float24.d.ts +8 -0
  438. package/lib/esm/_holo/spectral/float24.js +64 -0
  439. package/lib/esm/_holo/spectral/float24.js.map +1 -0
  440. package/lib/esm/_holo/spectral/spd.d.ts +22 -0
  441. package/lib/esm/_holo/spectral/spd.js +130 -0
  442. package/lib/esm/_holo/spectral/spd.js.map +1 -0
  443. package/lib/esm/_holo/spectral/tables.d.ts +62 -0
  444. package/lib/esm/_holo/spectral/tables.js +372 -0
  445. package/lib/esm/_holo/spectral/tables.js.map +1 -0
  446. package/lib/esm/_holo/tier.d.ts +4 -0
  447. package/lib/esm/_holo/tier.js +106 -0
  448. package/lib/esm/_holo/tier.js.map +1 -0
  449. package/lib/esm/_holo/types.d.ts +148 -0
  450. package/lib/esm/_holo/types.js +11 -0
  451. package/lib/esm/_holo/types.js.map +1 -0
  452. package/lib/esm/_kernel-worker.d.ts +22 -0
  453. package/lib/esm/_kernel-worker.js +169 -0
  454. package/lib/esm/_kernel-worker.js.map +1 -0
  455. package/lib/esm/_orbit-camera.d.ts +175 -0
  456. package/lib/esm/_orbit-camera.js +360 -0
  457. package/lib/esm/_orbit-camera.js.map +1 -0
  458. package/lib/esm/_pad.d.ts +2 -0
  459. package/lib/esm/_pad.js +10 -0
  460. package/lib/esm/_pad.js.map +1 -1
  461. package/lib/esm/_scene3d.d.ts +101 -0
  462. package/lib/esm/_scene3d.js +783 -0
  463. package/lib/esm/_scene3d.js.map +1 -0
  464. package/lib/esm/_shape-kernel-source.d.ts +2 -0
  465. package/lib/esm/_shape-kernel-source.js +5 -0
  466. package/lib/esm/_shape-kernel-source.js.map +1 -0
  467. package/lib/esm/_shape-worker.d.ts +8 -0
  468. package/lib/esm/_shape-worker.js +23 -0
  469. package/lib/esm/_shape-worker.js.map +1 -0
  470. package/lib/esm/_silhouette.d.ts +88 -0
  471. package/lib/esm/_silhouette.js +436 -0
  472. package/lib/esm/_silhouette.js.map +1 -0
  473. package/lib/esm/_simplex3.d.ts +2 -0
  474. package/lib/esm/_simplex3.js +157 -0
  475. package/lib/esm/_simplex3.js.map +1 -0
  476. package/lib/esm/_source.d.ts +80 -0
  477. package/lib/esm/_source.js +187 -0
  478. package/lib/esm/_source.js.map +1 -0
  479. package/lib/esm/_sphere-foam.d.ts +34 -0
  480. package/lib/esm/_sphere-foam.js +131 -0
  481. package/lib/esm/_sphere-foam.js.map +1 -0
  482. package/lib/esm/_thin-film.d.ts +26 -0
  483. package/lib/esm/_thin-film.js +140 -0
  484. package/lib/esm/_thin-film.js.map +1 -0
  485. package/lib/esm/bloom.js +40 -106
  486. package/lib/esm/bloom.js.map +1 -1
  487. package/lib/esm/bubble.d.ts +284 -0
  488. package/lib/esm/bubble.js +1816 -0
  489. package/lib/esm/bubble.js.map +1 -0
  490. package/lib/esm/glass.d.ts +254 -0
  491. package/lib/esm/glass.js +977 -0
  492. package/lib/esm/glass.js.map +1 -0
  493. package/lib/esm/holo-static.d.ts +3 -0
  494. package/lib/esm/holo-static.js +13 -0
  495. package/lib/esm/holo-static.js.map +1 -0
  496. package/lib/esm/holo.d.ts +401 -0
  497. package/lib/esm/holo.js +1606 -0
  498. package/lib/esm/holo.js.map +1 -0
  499. package/lib/esm/index.d.ts +18 -9
  500. package/lib/esm/index.js +7 -2
  501. package/lib/esm/index.js.map +1 -1
  502. package/lib/esm/jpeg-glitch.js +32 -29
  503. package/lib/esm/jpeg-glitch.js.map +1 -1
  504. package/lib/esm/matrix.d.ts +1 -1
  505. package/lib/esm/package.json +20 -5
  506. package/lib/esm/swirl-particle.d.ts +257 -0
  507. package/lib/esm/swirl-particle.js +2342 -0
  508. package/lib/esm/swirl-particle.js.map +1 -0
  509. package/lib/esm/voronoi.js +2 -75
  510. package/lib/esm/voronoi.js.map +1 -1
  511. package/package.json +38 -11
@@ -0,0 +1,1044 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.buildFoam = exports.buildSphereGrid = exports.placeBubbles = exports.insideDistance = exports.sampleSd2 = exports.hash4 = exports.fillShape = exports.SPHERE_BULGE_Z = exports.SPHERE_PROTRUDE = exports.BUBBLE_MAX_COUNT = exports.BUBBLE_LIST_MAX = exports.BUBBLE_TEX_W = void 0;
5
+ exports.bubbleKernel = bubbleKernel;
6
+ /**
7
+ * The placement and the grids as one self-contained function: a worker
8
+ * runs it from its source text (see `_kernel-worker.ts` and
9
+ * `scripts/gen-bubble-kernel.mjs`), so nothing in it may refer to
10
+ * anything outside it.
11
+ */
12
+ function bubbleKernel() {
13
+ /** Width of the data textures, in texels. */
14
+ const BUBBLE_TEX_W = 1024;
15
+ /** Spheres a grid cell lists at most (the shader's bound). */
16
+ const BUBBLE_LIST_MAX = 24;
17
+ /** Spheres placed at most. */
18
+ const BUBBLE_MAX_COUNT = 4096;
19
+ // A big bubble's radius per cell size.
20
+ const SPHERE_R = 0.86;
21
+ // Least distance between two big bubbles' centres, per diameter, at
22
+ // roundness 0 (heavy overlap: flat walls) and 1 (spheres that touch).
23
+ const SPACING_FLAT = 0.3;
24
+ const SPACING_ROUND = 1.0;
25
+ // A filling sphere's radius per clearance at roundness 0 and 1: it cuts
26
+ // into its neighbours by (k - 1) times its clearance. At most 2, so the
27
+ // spheres placed before keep their centres (no empty cells).
28
+ const FILL_K_FLAT = 1.8;
29
+ const FILL_K_ROUND = 1.06;
30
+ // A filling sphere pokes out of the shape by this share of its radius at
31
+ // most (and by the big bubbles' limit).
32
+ const FILL_POKE = 0.3;
33
+ const FILL_POKE_K = FILL_POKE / (1 - FILL_POKE);
34
+ // A filling sphere held back by the shape cuts into its nearest
35
+ // neighbour by this much anyway, when that pokes out by little.
36
+ const FILL_REACH = 1.15;
37
+ // How far a bubble may poke out of the silhouette, and how much further
38
+ // out of the front and back, per cell size.
39
+ const SPHERE_PROTRUDE = 0.3;
40
+ const SPHERE_BULGE_Z = 0.3;
41
+ // The big bubbles' centres stay this deep inside the outline, and this
42
+ // far from the front and back (as far as the depth allows), per cell size.
43
+ const CENTRE_DEPTH = 0.1;
44
+ const CENTRE_Z_MARGIN = 0.35;
45
+ // Candidates tried round each centre before it is retired.
46
+ const POISSON_TRIES = 30;
47
+ // Voxels of the fill's clearance field, at most, and their size per
48
+ // cell size, at least.
49
+ const FILL_VOXELS_MAX = 1 << 21;
50
+ const FILL_VOXEL_MIN = 1 / 16;
51
+ // Buckets of the fill's queue.
52
+ const BUCKETS = 256;
53
+ // Shrink of the grid's cells per refinement, refinements at most, and
54
+ // cells at most.
55
+ const GRID_SHRINK = 0.8;
56
+ const GRID_TRIES = 16;
57
+ const GRID_MAX_CELLS = 1 << 21;
58
+ /** How far a sphere may poke out of the shape, from the options. */
59
+ function fillShape(o) {
60
+ return {
61
+ protrude: SPHERE_PROTRUDE * o.cellSize,
62
+ bulgeZ: SPHERE_BULGE_Z * o.cellSize,
63
+ };
64
+ }
65
+ // ---- the shader's hash, in uint32 ----
66
+ function pcg3d(x, y, z) {
67
+ x = (Math.imul(x, 1664525) + 1013904223) >>> 0;
68
+ y = (Math.imul(y, 1664525) + 1013904223) >>> 0;
69
+ z = (Math.imul(z, 1664525) + 1013904223) >>> 0;
70
+ x = (x + Math.imul(y, z)) >>> 0;
71
+ y = (y + Math.imul(z, x)) >>> 0;
72
+ z = (z + Math.imul(x, y)) >>> 0;
73
+ x = (x ^ (x >>> 16)) >>> 0;
74
+ y = (y ^ (y >>> 16)) >>> 0;
75
+ z = (z ^ (z >>> 16)) >>> 0;
76
+ x = (x + Math.imul(y, z)) >>> 0;
77
+ y = (y + Math.imul(z, x)) >>> 0;
78
+ z = (z + Math.imul(x, y)) >>> 0;
79
+ return [x, y, z];
80
+ }
81
+ /** The shader's `hash4`: four uniform numbers in [0, 1] from a cell. */
82
+ function hash4(seed, x, y, z) {
83
+ const s = seed >>> 0;
84
+ const [a, b, c] = pcg3d((x ^ s) >>> 0, (y ^ Math.imul(s, 7)) >>> 0, (z ^ Math.imul(s, 13)) >>> 0);
85
+ let w = Math.imul(a ^ (b >>> 11) ^ (c << 7), 747796405) >>> 0;
86
+ w = (w ^ (w >>> 16)) >>> 0;
87
+ const n = 1 / 4294967295;
88
+ return [a * n, b * n, c * n, w * n];
89
+ }
90
+ function mulberry32(seed) {
91
+ let a = seed >>> 0;
92
+ return () => {
93
+ a = (a + 0x6d2b79f5) >>> 0;
94
+ let t = a;
95
+ t = Math.imul(t ^ (t >>> 15), t | 1);
96
+ t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
97
+ return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
98
+ };
99
+ }
100
+ // ---- the shape ----
101
+ /**
102
+ * The 2D field at (x, y), bilinear as the shader's `sd2`: signed distance
103
+ * (world units, negative inside) and unit gradient.
104
+ */
105
+ function sampleSd2(shape, x, y) {
106
+ const [rx, ry, rw, rh] = shape.sdfRect;
107
+ const W = shape.sdfW;
108
+ const H = shape.sdfH;
109
+ const u = (x - rx) / rw;
110
+ const v = (y - ry) / rh;
111
+ const cu = Math.min(Math.max(u, 0), 1);
112
+ const cv = Math.min(Math.max(v, 0), 1);
113
+ const ox = (u - cu) * rw;
114
+ const oy = (v - cv) * rh;
115
+ const out = Math.hypot(ox, oy);
116
+ const fx = Math.min(Math.max(cu * W - 0.5, 0), W - 1);
117
+ const fy = Math.min(Math.max(cv * H - 0.5, 0), H - 1);
118
+ const x0 = Math.floor(fx);
119
+ const y0 = Math.floor(fy);
120
+ const x1 = Math.min(x0 + 1, W - 1);
121
+ const y1 = Math.min(y0 + 1, H - 1);
122
+ const tx = fx - x0;
123
+ const ty = fy - y0;
124
+ const s = shape.sdf;
125
+ const i00 = (y0 * W + x0) * 4;
126
+ const i10 = (y0 * W + x1) * 4;
127
+ const i01 = (y1 * W + x0) * 4;
128
+ const i11 = (y1 * W + x1) * 4;
129
+ const w00 = (1 - tx) * (1 - ty);
130
+ const w10 = tx * (1 - ty);
131
+ const w01 = (1 - tx) * ty;
132
+ const w11 = tx * ty;
133
+ const d = s[i00] * w00 + s[i10] * w10 + s[i01] * w01 + s[i11] * w11;
134
+ let gx = s[i00 + 1] * w00 +
135
+ s[i10 + 1] * w10 +
136
+ s[i01 + 1] * w01 +
137
+ s[i11 + 1] * w11;
138
+ let gy = s[i00 + 2] * w00 +
139
+ s[i10 + 2] * w10 +
140
+ s[i01 + 2] * w01 +
141
+ s[i11 + 2] * w11;
142
+ if (out > 0) {
143
+ gx = ox / out + gx * 0.05;
144
+ gy = oy / out + gy * 0.05;
145
+ }
146
+ const gl = Math.hypot(gx, gy);
147
+ return gl > 1e-5 ? [d + out, gx / gl, gy / gl] : [d + out, 0, 1];
148
+ }
149
+ /** Distance into the extruded shape (sharp edges), negative outside. */
150
+ function insideDistance(shape, halfDepth, x, y, z) {
151
+ return Math.min(-sampleSd2(shape, x, y)[0], halfDepth - Math.abs(z));
152
+ }
153
+ // The extrusion's signed distance from the 2D one (a) and |z| - halfDepth
154
+ // (b), with the edges rounded by `bevel`, positive outside (as the
155
+ // shader's \`extrude\`).
156
+ function extrudeSd(a, b, bevel) {
157
+ const wx = a + bevel;
158
+ const wy = b + bevel;
159
+ return wx > 0 && wy > 0
160
+ ? Math.hypot(wx, wy) - bevel
161
+ : Math.max(wx, wy) - bevel;
162
+ }
163
+ // The extruded shape's signed distance, positive outside.
164
+ function sd3(shape, halfDepth, bevel, x, y, z) {
165
+ const a = sampleSd2(shape, x, y)[0];
166
+ return extrudeSd(a, Math.abs(z) - halfDepth, bevel);
167
+ }
168
+ // ---- spheres near a point ----
169
+ // A hash grid of sphere centres, for the neighbours of a new sphere.
170
+ class CentreGrid {
171
+ #cell;
172
+ #map = new Map();
173
+ constructor(cell) {
174
+ this.#cell = cell;
175
+ }
176
+ #key(i, j, k) {
177
+ return ((i + 1024) * 2048 + (j + 1024)) * 2048 + (k + 1024);
178
+ }
179
+ add(id, x, y, z) {
180
+ const c = this.#cell;
181
+ const key = this.#key(Math.floor(x / c), Math.floor(y / c), Math.floor(z / c));
182
+ const list = this.#map.get(key);
183
+ if (list) {
184
+ list.push(id);
185
+ }
186
+ else {
187
+ this.#map.set(key, [id]);
188
+ }
189
+ }
190
+ /** Calls `f` with every sphere whose centre may be within `r`. */
191
+ near(x, y, z, r, f) {
192
+ const c = this.#cell;
193
+ const i0 = Math.floor((x - r) / c);
194
+ const i1 = Math.floor((x + r) / c);
195
+ const j0 = Math.floor((y - r) / c);
196
+ const j1 = Math.floor((y + r) / c);
197
+ const k0 = Math.floor((z - r) / c);
198
+ const k1 = Math.floor((z + r) / c);
199
+ for (let k = k0; k <= k1; k++) {
200
+ for (let j = j0; j <= j1; j++) {
201
+ for (let i = i0; i <= i1; i++) {
202
+ const list = this.#map.get(this.#key(i, j, k));
203
+ if (list) {
204
+ for (const id of list) {
205
+ f(id);
206
+ }
207
+ }
208
+ }
209
+ }
210
+ }
211
+ }
212
+ }
213
+ // ---- placement ----
214
+ // How much the cells grow per try when the big bubbles do not fit,
215
+ // and the tries at most.
216
+ const CELL_GROW = 1.12;
217
+ const CELL_GROW_TRIES = 40;
218
+ // The row of spheres in a part too thin for the fill: how far from
219
+ // every sphere its first one is (per smallest gap), how close to a
220
+ // sphere a point counts as covered (per radius), the smallest radius
221
+ // (in texels of the field), and the sweeps at most.
222
+ const THIN_FAR = 2;
223
+ const THIN_COVERED = 0.25;
224
+ const THIN_TEXELS = 1.5;
225
+ const THIN_PASSES = 8;
226
+ /**
227
+ * The bubbles in the extruded shape: the lattice's, then the fill's.
228
+ * Deterministic for the options.
229
+ */
230
+ function placeBubbles(shape, o) {
231
+ // Too many big bubbles for the shape: grow the cells until they
232
+ // fit, so the whole shape is covered.
233
+ let cell = Math.max(o.cellSize, 1e-3);
234
+ for (let i = 0; i < CELL_GROW_TRIES; i++) {
235
+ const fill = placeAt(shape, o, cell, true);
236
+ if (fill) {
237
+ return fill;
238
+ }
239
+ cell *= CELL_GROW;
240
+ }
241
+ return placeAt(shape, o, cell, false);
242
+ }
243
+ // The bubbles for a cell size. With `fit`, null when the big bubbles
244
+ // alone would take more than their share of `maxCount`.
245
+ function placeAt(shape, o, cell, fit) {
246
+ const halfDepth = Math.max(o.halfDepth, 1e-3);
247
+ const bevel = Math.min(Math.max(o.bevel ?? 0, 0), halfDepth);
248
+ const roundness = Math.min(Math.max(o.roundness, 0), 1);
249
+ const radiusVar = Math.min(Math.max(o.cellSizeRandomness, 0), 1);
250
+ const seed = o.seed >>> 0;
251
+ const maxCount = Math.min(Math.max(Math.floor(o.maxCount ?? BUBBLE_MAX_COUNT), 0), BUBBLE_MAX_COUNT);
252
+ // With a fill, the big bubbles leave it half the count.
253
+ const latticeMax = o.minSize < 1 ? Math.max(Math.floor(maxCount / 2), 1) : maxCount;
254
+ const { protrude, bulgeZ } = fillShape({ ...o, cellSize: cell });
255
+ const sphereR = SPHERE_R * cell;
256
+ // The big bubbles' centres: Bridson's Poisson disk sampling, grown
257
+ // from seeds on a coarse grid (in random order) so every part of
258
+ // the shape gets some, however small.
259
+ const spacing = 2 *
260
+ sphereR *
261
+ (SPACING_FLAT + (SPACING_ROUND - SPACING_FLAT) * roundness);
262
+ const centreDepth = CENTRE_DEPTH * cell;
263
+ const zLim = Math.max(halfDepth - CENTRE_Z_MARGIN * cell, 0);
264
+ // Thinner than this, the centres spread over a plane.
265
+ const flat = zLim < 0.5 * spacing;
266
+ const [rx, ry, rw, rh] = shape.sdfRect;
267
+ const rand = mulberry32(Math.imul(seed, 0x27d4eb2d) ^ 0x165667b1);
268
+ const valid = (x, y, z) => Math.abs(z) <= zLim && sampleSd2(shape, x, y)[0] <= -centreDepth;
269
+ // A background grid with one centre per cell at most.
270
+ const g = spacing / Math.sqrt(3);
271
+ const gnx = Math.max(1, Math.ceil(rw / g));
272
+ const gny = Math.max(1, Math.ceil(rh / g));
273
+ const gnz = Math.max(1, Math.ceil((2 * zLim) / g));
274
+ const owner = new Int32Array(gnx * gny * gnz).fill(-1);
275
+ const gi = (v, o, n) => Math.min(n - 1, Math.max(0, Math.floor((v - o) / g)));
276
+ const pts = [];
277
+ const free = (x, y, z) => {
278
+ const i = gi(x, rx, gnx);
279
+ const j = gi(y, ry, gny);
280
+ const k = gi(z, -zLim, gnz);
281
+ for (let kk = Math.max(0, k - 2); kk <= Math.min(gnz - 1, k + 2); kk++) {
282
+ for (let jj = Math.max(0, j - 2); jj <= Math.min(gny - 1, j + 2); jj++) {
283
+ for (let ii = Math.max(0, i - 2); ii <= Math.min(gnx - 1, i + 2); ii++) {
284
+ const q = owner[(kk * gny + jj) * gnx + ii];
285
+ if (q < 0) {
286
+ continue;
287
+ }
288
+ const dx = pts[q * 3] - x;
289
+ const dy = pts[q * 3 + 1] - y;
290
+ const dz = pts[q * 3 + 2] - z;
291
+ if (dx * dx + dy * dy + dz * dz < spacing * spacing) {
292
+ return false;
293
+ }
294
+ }
295
+ }
296
+ }
297
+ return true;
298
+ };
299
+ const active = [];
300
+ const add = (x, y, z) => {
301
+ const n = pts.length / 3;
302
+ pts.push(x, y, z);
303
+ owner[(gi(z, -zLim, gnz) * gny + gi(y, ry, gny)) * gnx +
304
+ gi(x, rx, gnx)] = n;
305
+ active.push(n);
306
+ };
307
+ // A candidate round centre q, between one and two spacings away.
308
+ const around = (q) => {
309
+ const a = rand() * Math.PI * 2;
310
+ if (flat) {
311
+ const d = spacing * Math.sqrt(1 + 3 * rand());
312
+ return [
313
+ pts[q * 3] + d * Math.cos(a),
314
+ pts[q * 3 + 1] + d * Math.sin(a),
315
+ (2 * rand() - 1) * zLim,
316
+ ];
317
+ }
318
+ const d = spacing * Math.cbrt(1 + 7 * rand());
319
+ const cz = 2 * rand() - 1;
320
+ const sz = Math.sqrt(1 - cz * cz);
321
+ return [
322
+ pts[q * 3] + d * sz * Math.cos(a),
323
+ pts[q * 3 + 1] + d * sz * Math.sin(a),
324
+ pts[q * 3 + 2] + d * cz,
325
+ ];
326
+ };
327
+ const seeds = [];
328
+ for (let y = ry + spacing / 2; y < ry + rh; y += spacing) {
329
+ for (let x = rx + spacing / 2; x < rx + rw; x += spacing) {
330
+ seeds.push(x, y);
331
+ }
332
+ }
333
+ for (let i = seeds.length / 2 - 1; i > 0; i--) {
334
+ const j = Math.floor(rand() * (i + 1));
335
+ for (let c = 0; c < 2; c++) {
336
+ const t = seeds[i * 2 + c];
337
+ seeds[i * 2 + c] = seeds[j * 2 + c];
338
+ seeds[j * 2 + c] = t;
339
+ }
340
+ }
341
+ for (let si = 0; si < seeds.length / 2 && pts.length / 3 < latticeMax; si++) {
342
+ const sx = seeds[si * 2];
343
+ const sy = seeds[si * 2 + 1];
344
+ const sz = (2 * rand() - 1) * zLim;
345
+ if (!valid(sx, sy, sz) || !free(sx, sy, sz)) {
346
+ continue;
347
+ }
348
+ add(sx, sy, sz);
349
+ while (active.length > 0 && pts.length / 3 < latticeMax) {
350
+ const e = Math.floor(rand() * active.length);
351
+ const q = active[e];
352
+ let found = false;
353
+ for (let t = 0; t < POISSON_TRIES; t++) {
354
+ const [x, y, z] = around(q);
355
+ if (valid(x, y, z) && free(x, y, z)) {
356
+ add(x, y, z);
357
+ found = true;
358
+ break;
359
+ }
360
+ }
361
+ if (!found) {
362
+ active[e] = active[active.length - 1];
363
+ active.pop();
364
+ }
365
+ }
366
+ active.length = 0;
367
+ }
368
+ if (fit && maxCount > 0 && pts.length / 3 >= latticeMax) {
369
+ return null;
370
+ }
371
+ // Their radii: random within cellSizeRandomness, and kept from
372
+ // poking out of the shape too far.
373
+ const lat = [];
374
+ for (let q = 0; q < pts.length / 3; q++) {
375
+ const cx = pts[q * 3];
376
+ const cy = pts[q * 3 + 1];
377
+ const cz = pts[q * 3 + 2];
378
+ const sd = sampleSd2(shape, cx, cy)[0];
379
+ let r = sphereR * (1 - radiusVar * rand());
380
+ r = Math.min(r, protrude -
381
+ extrudeSd(sd, Math.abs(cz) - halfDepth - bulgeZ, bevel));
382
+ if (r > 0) {
383
+ lat.push(cx, cy, cz, r);
384
+ }
385
+ }
386
+ // Leave out lattice spheres that do not own their own centre.
387
+ const centres = new CentreGrid(cell);
388
+ const nLat = lat.length / 4;
389
+ let maxR = 0;
390
+ for (let i = 0; i < nLat; i++) {
391
+ centres.add(i, lat[i * 4], lat[i * 4 + 1], lat[i * 4 + 2]);
392
+ maxR = Math.max(maxR, lat[i * 4 + 3]);
393
+ }
394
+ const out = [];
395
+ for (let i = 0; i < nLat && out.length / 4 < maxCount; i++) {
396
+ const x = lat[i * 4];
397
+ const y = lat[i * 4 + 1];
398
+ const z = lat[i * 4 + 2];
399
+ const own = -lat[i * 4 + 3] * lat[i * 4 + 3];
400
+ let owned = true;
401
+ centres.near(x, y, z, maxR, (j) => {
402
+ if (j === i) {
403
+ return;
404
+ }
405
+ const dx = x - lat[j * 4];
406
+ const dy = y - lat[j * 4 + 1];
407
+ const dz = z - lat[j * 4 + 2];
408
+ const pj = dx * dx + dy * dy + dz * dz - lat[j * 4 + 3] ** 2;
409
+ if (pj < own || (pj === own && j < i)) {
410
+ owned = false;
411
+ }
412
+ });
413
+ if (owned) {
414
+ out.push(x, y, z, lat[i * 4 + 3]);
415
+ }
416
+ }
417
+ const latticeCount = out.length / 4;
418
+ // The fill.
419
+ const tMin = 0.5 * Math.max(o.minSize, 0) * cell;
420
+ let voxel = 0;
421
+ let voxels = 0;
422
+ if (o.minSize < 1 && tMin > 0 && out.length / 4 < maxCount) {
423
+ const k = FILL_K_FLAT + (FILL_K_ROUND - FILL_K_FLAT) * roundness;
424
+ const rand = mulberry32(Math.imul(seed, 2654435761) ^ 0x9e3779b9);
425
+ // The voxels over the shape's box. Only those inside the shape
426
+ // are candidates for a centre.
427
+ let bx0 = Infinity;
428
+ let bx1 = -Infinity;
429
+ let by0 = Infinity;
430
+ let by1 = -Infinity;
431
+ {
432
+ const W = shape.sdfW;
433
+ const H = shape.sdfH;
434
+ for (let j = 0; j < H; j++) {
435
+ for (let i = 0; i < W; i++) {
436
+ if (shape.sdf[(j * W + i) * 4] < 0) {
437
+ const x = rx + ((i + 0.5) / W) * rw;
438
+ const y = ry + ((j + 0.5) / H) * rh;
439
+ bx0 = Math.min(bx0, x);
440
+ bx1 = Math.max(bx1, x);
441
+ by0 = Math.min(by0, y);
442
+ by1 = Math.max(by1, y);
443
+ }
444
+ }
445
+ }
446
+ }
447
+ if (bx0 <= bx1) {
448
+ const ext = [bx1 - bx0, by1 - by0, 2 * halfDepth];
449
+ let h = Math.max(tMin, cell * FILL_VOXEL_MIN);
450
+ h = Math.max(h, Math.cbrt((ext[0] * ext[1] * ext[2]) / FILL_VOXELS_MAX));
451
+ const nx = Math.max(1, Math.ceil(ext[0] / h));
452
+ const ny = Math.max(1, Math.ceil(ext[1] / h));
453
+ const nz = Math.max(1, Math.ceil(ext[2] / h));
454
+ const x0 = (bx0 + bx1) / 2 - ((nx - 1) * h) / 2;
455
+ const y0 = (by0 + by1) / 2 - ((ny - 1) * h) / 2;
456
+ const z0 = -((nz - 1) * h) / 2;
457
+ const nxy = nx * ny;
458
+ voxel = h;
459
+ voxels = nxy * nz;
460
+ // dB: the radius the shape allows; dS: the gap to the
461
+ // spheres; clear = min(dS, dB), -1 for a non-candidate.
462
+ const col = new Float32Array(nxy);
463
+ for (let j = 0; j < ny; j++) {
464
+ for (let i = 0; i < nx; i++) {
465
+ col[j * nx + i] = -sampleSd2(shape, x0 + i * h, y0 + j * h)[0];
466
+ }
467
+ }
468
+ const dB = new Float32Array(voxels);
469
+ const dS = new Float32Array(voxels).fill(Infinity);
470
+ const clear = new Float32Array(voxels).fill(-1);
471
+ let bMax = 0;
472
+ for (let kk = 0; kk < nz; kk++) {
473
+ const dz = halfDepth - Math.abs(z0 + kk * h);
474
+ for (let j = 0; j < nxy; j++) {
475
+ const v = kk * nxy + j;
476
+ // Into the shape, rounded edges included.
477
+ const d = -extrudeSd(-col[j], -dz, bevel);
478
+ if (d > 0) {
479
+ // A filling sphere pokes out of the shape by a
480
+ // share of its radius at most, so the small ones
481
+ // along the outline keep it crisp.
482
+ dB[v] = Math.min(col[j] +
483
+ Math.min(protrude, FILL_POKE_K * col[j]), dz +
484
+ Math.min(protrude + bulgeZ, FILL_POKE_K * dz), d + Math.min(protrude, FILL_POKE_K * d));
485
+ bMax = Math.max(bMax, dB[v]);
486
+ }
487
+ else {
488
+ dB[v] = -1;
489
+ }
490
+ }
491
+ }
492
+ // Lower dS round a sphere, for the voxels within `cap` of its
493
+ // surface (beyond, the clearance is less than the gap).
494
+ const carve = (cx, cy, cz, r, cap, onLower) => {
495
+ const reach = r + cap;
496
+ const i0 = Math.max(0, Math.ceil((cx - reach - x0) / h));
497
+ const i1 = Math.min(nx - 1, Math.floor((cx + reach - x0) / h));
498
+ const j0 = Math.max(0, Math.ceil((cy - reach - y0) / h));
499
+ const j1 = Math.min(ny - 1, Math.floor((cy + reach - y0) / h));
500
+ const k0 = Math.max(0, Math.ceil((cz - reach - z0) / h));
501
+ const k1 = Math.min(nz - 1, Math.floor((cz + reach - z0) / h));
502
+ const r2 = reach * reach;
503
+ for (let kk = k0; kk <= k1; kk++) {
504
+ const dz = z0 + kk * h - cz;
505
+ for (let j = j0; j <= j1; j++) {
506
+ const dy = y0 + j * h - cy;
507
+ const dyz = dy * dy + dz * dz;
508
+ if (dyz > r2) {
509
+ continue;
510
+ }
511
+ const row = kk * nxy + j * nx;
512
+ for (let i = i0; i <= i1; i++) {
513
+ const v = row + i;
514
+ if (dB[v] < 0) {
515
+ continue;
516
+ }
517
+ const dx = x0 + i * h - cx;
518
+ const d2 = dx * dx + dyz;
519
+ if (d2 > r2) {
520
+ continue;
521
+ }
522
+ const g = Math.sqrt(d2) - r;
523
+ if (g < dS[v]) {
524
+ dS[v] = g;
525
+ onLower?.(v);
526
+ }
527
+ }
528
+ }
529
+ }
530
+ };
531
+ for (let s = 0; s < latticeCount; s++) {
532
+ carve(out[s * 4], out[s * 4 + 1], out[s * 4 + 2], out[s * 4 + 3], bMax);
533
+ }
534
+ // The queue: buckets of clearance over [tMin, bMax], lazy.
535
+ const span = Math.max(bMax - tMin, 1e-9);
536
+ const bucketOf = (c) => Math.min(BUCKETS - 1, Math.floor(((c - tMin) / span) * BUCKETS));
537
+ const buckets = [];
538
+ for (let b = 0; b < BUCKETS; b++) {
539
+ buckets.push([]);
540
+ }
541
+ for (let v = 0; v < voxels; v++) {
542
+ if (dB[v] < 0) {
543
+ continue;
544
+ }
545
+ const c = Math.min(dS[v], dB[v]);
546
+ clear[v] = c;
547
+ if (c >= tMin) {
548
+ buckets[bucketOf(c)].push(v);
549
+ }
550
+ }
551
+ const fill = new CentreGrid(cell);
552
+ for (let s = 0; s < latticeCount; s++) {
553
+ fill.add(s, out[s * 4], out[s * 4 + 1], out[s * 4 + 2]);
554
+ }
555
+ let top = BUCKETS - 1;
556
+ const lower = (v) => {
557
+ const c = Math.min(dS[v], dB[v]);
558
+ const old = clear[v];
559
+ if (c < old) {
560
+ clear[v] = c;
561
+ if (c >= tMin && bucketOf(c) !== bucketOf(old)) {
562
+ buckets[bucketOf(c)].push(v);
563
+ }
564
+ }
565
+ };
566
+ while (out.length / 4 < maxCount) {
567
+ while (top >= 0 && buckets[top].length === 0) {
568
+ top--;
569
+ }
570
+ if (top < 0) {
571
+ break;
572
+ }
573
+ // A random entry of the top bucket; skip stale ones.
574
+ const list = buckets[top];
575
+ const e = Math.floor(rand() * list.length);
576
+ const v = list[e];
577
+ list[e] = list[list.length - 1];
578
+ list.pop();
579
+ const c = clear[v];
580
+ if (c < tMin || bucketOf(c) !== top) {
581
+ continue;
582
+ }
583
+ const kk = Math.floor(v / nxy);
584
+ const j = Math.floor((v - kk * nxy) / nx);
585
+ const i = v - kk * nxy - j * nx;
586
+ const cx = x0 + i * h;
587
+ const cy = y0 + j * h;
588
+ const cz = z0 + kk * h;
589
+ // Larger than the gap, so it cuts into its neighbours; no
590
+ // larger than the shape allows, and small enough that
591
+ // every neighbour keeps its centre.
592
+ // Far from every sphere, the gap is not tracked: such
593
+ // a voxel is in a part too thin for a big bubble.
594
+ // Measure the gap, so its spheres join up.
595
+ const far = dS[v] === Infinity;
596
+ let gap = dS[v];
597
+ if (far) {
598
+ fill.near(cx, cy, cz, dB[v] + tMin + maxR, (s) => {
599
+ const d = Math.hypot(cx - out[s * 4], cy - out[s * 4 + 1], cz - out[s * 4 + 2]) - out[s * 4 + 3];
600
+ gap = Math.min(gap, d);
601
+ });
602
+ }
603
+ let r = Math.min(k * gap, dB[v]);
604
+ // One held back by the shape just short of its nearest
605
+ // neighbour may poke out a little more to reach it, so
606
+ // it shares a wall rather than floating loose.
607
+ const reachIt = FILL_REACH * gap;
608
+ if (r < reachIt && reachIt <= dB[v] + tMin) {
609
+ r = reachIt;
610
+ }
611
+ if (r <= gap && !far) {
612
+ // It could not reach any neighbour: a loose bubble
613
+ // in a pocket of the outline. Leave the gap.
614
+ clear[v] = -1;
615
+ continue;
616
+ }
617
+ const n0 = out.length / 4;
618
+ fill.near(cx, cy, cz, r, (s) => {
619
+ const dx = cx - out[s * 4];
620
+ const dy = cy - out[s * 4 + 1];
621
+ const dz = cz - out[s * 4 + 2];
622
+ const lim = 0.98 *
623
+ Math.sqrt(dx * dx +
624
+ dy * dy +
625
+ dz * dz +
626
+ out[s * 4 + 3] ** 2);
627
+ if (lim < r) {
628
+ r = lim;
629
+ }
630
+ });
631
+ out.push(cx, cy, cz, r);
632
+ fill.add(n0, cx, cy, cz);
633
+ maxR = Math.max(maxR, r);
634
+ // Upper bound of every clearance left: the top bucket's.
635
+ const cap = tMin + ((top + 1) / BUCKETS) * span;
636
+ carve(cx, cy, cz, r, cap, lower);
637
+ // The voxel itself is inside the new sphere now.
638
+ clear[v] = Math.min(clear[v], -r);
639
+ }
640
+ // The parts too thin for the fill's smallest sphere, with
641
+ // no sphere near: a row of smaller ones along their middle.
642
+ const thinStart = out.length / 4;
643
+ const W = shape.sdfW;
644
+ const H = shape.sdfH;
645
+ const texel = Math.max(rw / W, rh / H);
646
+ const raw = (i, j) => shape.sdf[(j * W + i) * 4];
647
+ // x, y, radius per texel on the middle line of a thin part.
648
+ const thin = [];
649
+ for (let j = 1; j < H - 1; j++) {
650
+ for (let i = 1; i < W - 1; i++) {
651
+ const d = raw(i, j);
652
+ if (!(d < 0) ||
653
+ d > raw(i - 1, j) ||
654
+ d > raw(i + 1, j) ||
655
+ d > raw(i, j - 1) ||
656
+ d > raw(i, j + 1) ||
657
+ d > raw(i - 1, j - 1) ||
658
+ d > raw(i + 1, j - 1) ||
659
+ d > raw(i - 1, j + 1) ||
660
+ d > raw(i + 1, j + 1)) {
661
+ continue;
662
+ }
663
+ const x = rx + ((i + 0.5) / W) * rw;
664
+ const y = ry + ((j + 0.5) / H) * rh;
665
+ const c = -sampleSd2(shape, x, y)[0];
666
+ const e = -extrudeSd(-c, -halfDepth, bevel);
667
+ if (!(e > 0)) {
668
+ continue;
669
+ }
670
+ const r = Math.min(c + Math.min(protrude, FILL_POKE_K * c), halfDepth +
671
+ Math.min(protrude + bulgeZ, FILL_POKE_K * halfDepth), e + Math.min(protrude, FILL_POKE_K * e));
672
+ if (r < tMin && r >= THIN_TEXELS * texel) {
673
+ thin.push([x, y, r]);
674
+ }
675
+ }
676
+ }
677
+ thin.sort((a, b) => b[2] - a[2]);
678
+ const done = new Uint8Array(thin.length);
679
+ let placedSome = true;
680
+ for (let pass = 0; pass < THIN_PASSES && placedSome; pass++) {
681
+ placedSome = false;
682
+ for (let t = 0; t < thin.length; t++) {
683
+ if (out.length / 4 >= maxCount) {
684
+ break;
685
+ }
686
+ if (done[t]) {
687
+ continue;
688
+ }
689
+ const [cx, cy, r0] = thin[t];
690
+ let gap = Infinity;
691
+ let nearest = -1;
692
+ fill.near(cx, cy, 0, THIN_FAR * tMin + maxR, (s) => {
693
+ const d = Math.hypot(cx - out[s * 4], cy - out[s * 4 + 1], out[s * 4 + 2]) - out[s * 4 + 3];
694
+ if (d < gap) {
695
+ gap = d;
696
+ nearest = s;
697
+ }
698
+ });
699
+ if (gap < THIN_COVERED * r0) {
700
+ done[t] = 1;
701
+ continue;
702
+ }
703
+ // The first of a part, or the next of its row.
704
+ const first = gap > THIN_FAR * tMin;
705
+ const next = nearest >= thinStart && gap < r0;
706
+ if (!first && !next) {
707
+ continue;
708
+ }
709
+ let r = r0;
710
+ fill.near(cx, cy, 0, r, (s) => {
711
+ const dx = cx - out[s * 4];
712
+ const dy = cy - out[s * 4 + 1];
713
+ const dz = out[s * 4 + 2];
714
+ const lim = 0.98 *
715
+ Math.sqrt(dx * dx +
716
+ dy * dy +
717
+ dz * dz +
718
+ out[s * 4 + 3] ** 2);
719
+ if (lim < r) {
720
+ r = lim;
721
+ }
722
+ });
723
+ fill.add(out.length / 4, cx, cy, 0);
724
+ out.push(cx, cy, 0, r);
725
+ maxR = Math.max(maxR, r);
726
+ done[t] = 1;
727
+ placedSome = true;
728
+ }
729
+ }
730
+ }
731
+ }
732
+ const spheres = new Float32Array(out);
733
+ const count = spheres.length / 4;
734
+ let reach = 0;
735
+ for (let s = 0; s < count; s++) {
736
+ const d = sd3(shape, halfDepth, bevel, spheres[s * 4], spheres[s * 4 + 1], spheres[s * 4 + 2]);
737
+ reach = Math.max(reach, d + spheres[s * 4 + 3]);
738
+ }
739
+ return {
740
+ spheres,
741
+ count,
742
+ latticeCount,
743
+ capped: count >= maxCount,
744
+ cellSize: cell,
745
+ reach,
746
+ voxel,
747
+ voxels,
748
+ };
749
+ }
750
+ // ---- the grid ----
751
+ /**
752
+ * The grid over the spheres: each cell lists every sphere whose ball,
753
+ * grown by `wobble` times its radius (its drift), touches the cell.
754
+ * With `fill` (what a container adds to every r² deep inside the
755
+ * shape), a sphere also reaches as far as its r² + fill does, but
756
+ * only into the cells where it can own a point: the fill is the same
757
+ * for all spheres, so it does not change which one has the least
758
+ * power. Cells start at `cell` and shrink until no list is longer
759
+ * than {@link BUBBLE_LIST_MAX}.
760
+ */
761
+ function buildSphereGrid(input, wobble, cell, fill = 0) {
762
+ let spheres = input;
763
+ let dropped = 0;
764
+ for (;;) {
765
+ const g = tryGrid(spheres, Math.max(wobble, 0), Math.max(cell, 1e-4), Math.max(fill, 0));
766
+ if (g.ok) {
767
+ return { ...g.grid, dropped };
768
+ }
769
+ // No grid fits: leave out the smallest sphere of each full cell.
770
+ const drop = new Set(g.drop);
771
+ const keep = [];
772
+ for (let s = 0; s < spheres.length / 4; s++) {
773
+ if (!drop.has(s)) {
774
+ keep.push(...spheres.subarray(s * 4, s * 4 + 4));
775
+ }
776
+ }
777
+ dropped += drop.size;
778
+ spheres = new Float32Array(keep);
779
+ }
780
+ }
781
+ function tryGrid(spheres, wobble, cell0, fill) {
782
+ const count = spheres.length / 4;
783
+ // How far a sphere reaches, drift included: with its own radius,
784
+ // and with the fill.
785
+ const own = (s) => spheres[s * 4 + 3] * (1 + wobble);
786
+ const reach = (s) => {
787
+ const r = spheres[s * 4 + 3];
788
+ return Math.sqrt(r * r + fill) + wobble * r;
789
+ };
790
+ const lo = [Infinity, Infinity, Infinity];
791
+ const hi = [-Infinity, -Infinity, -Infinity];
792
+ for (let s = 0; s < count; s++) {
793
+ const r = reach(s);
794
+ for (let a = 0; a < 3; a++) {
795
+ lo[a] = Math.min(lo[a], spheres[s * 4 + a] - r);
796
+ hi[a] = Math.max(hi[a], spheres[s * 4 + a] + r);
797
+ }
798
+ }
799
+ if (count === 0) {
800
+ lo.fill(0);
801
+ hi.fill(1e-3);
802
+ }
803
+ const size = [hi[0] - lo[0], hi[1] - lo[1], hi[2] - lo[2]];
804
+ let cell = Math.max(cell0, Math.cbrt((size[0] * size[1] * size[2]) / GRID_MAX_CELLS));
805
+ let refinements = 0;
806
+ for (;;) {
807
+ const dims = [
808
+ Math.max(1, Math.ceil(size[0] / cell)),
809
+ Math.max(1, Math.ceil(size[1] / cell)),
810
+ Math.max(1, Math.ceil(size[2] / cell)),
811
+ ];
812
+ const cells = dims[0] * dims[1] * dims[2];
813
+ const counts = new Int32Array(cells);
814
+ let maxList = 0;
815
+ // Every sphere that reaches a cell, with the nearest and the
816
+ // farthest distance from its centre to the cell.
817
+ const pairs = (f) => {
818
+ for (let s = 0; s < count; s++) {
819
+ const cx = spheres[s * 4];
820
+ const cy = spheres[s * 4 + 1];
821
+ const cz = spheres[s * 4 + 2];
822
+ const r = reach(s);
823
+ const c = [cx, cy, cz];
824
+ const a0 = c.map((v, a) => Math.max(0, Math.floor((v - r - lo[a]) / cell)));
825
+ const a1 = c.map((v, a) => Math.min(dims[a] - 1, Math.floor((v + r - lo[a]) / cell)));
826
+ for (let z = a0[2]; z <= a1[2]; z++) {
827
+ const bz = lo[2] + z * cell;
828
+ const ez = Math.max(bz - cz, 0, cz - bz - cell);
829
+ const fz = Math.max(Math.abs(bz - cz), Math.abs(bz + cell - cz));
830
+ for (let y = a0[1]; y <= a1[1]; y++) {
831
+ const by = lo[1] + y * cell;
832
+ const ey = Math.max(by - cy, 0, cy - by - cell);
833
+ const fy = Math.max(Math.abs(by - cy), Math.abs(by + cell - cy));
834
+ for (let x = a0[0]; x <= a1[0]; x++) {
835
+ const bx = lo[0] + x * cell;
836
+ const ex = Math.max(bx - cx, 0, cx - bx - cell);
837
+ const near2 = ex * ex + ey * ey + ez * ez;
838
+ if (near2 > r * r) {
839
+ continue;
840
+ }
841
+ const fx = Math.max(Math.abs(bx - cx), Math.abs(bx + cell - cx));
842
+ f(s, x + dims[0] * (y + dims[1] * z), Math.sqrt(near2), Math.sqrt(fx * fx + fy * fy + fz * fz));
843
+ }
844
+ }
845
+ }
846
+ }
847
+ };
848
+ // With the fill, the least power any point of a cell can have
849
+ // is at most minU; a sphere whose power stays above it over the
850
+ // whole cell owns no point there.
851
+ let minU = null;
852
+ if (fill > 0) {
853
+ const m = new Float64Array(cells).fill(Infinity);
854
+ pairs((s, id, _near, far) => {
855
+ const r = spheres[s * 4 + 3];
856
+ const u = (far + wobble * r) ** 2 - r * r;
857
+ if (u < m[id]) {
858
+ m[id] = u;
859
+ }
860
+ });
861
+ minU = m;
862
+ }
863
+ const each = (f) => {
864
+ pairs((s, id, near) => {
865
+ if (minU && near > own(s)) {
866
+ const r = spheres[s * 4 + 3];
867
+ const l = Math.max(near - wobble * r, 0) ** 2 - r * r;
868
+ if (l > minU[id]) {
869
+ return;
870
+ }
871
+ }
872
+ f(s, id);
873
+ });
874
+ };
875
+ each((_s, id) => {
876
+ counts[id]++;
877
+ });
878
+ for (let id = 0; id < cells; id++) {
879
+ maxList = Math.max(maxList, counts[id]);
880
+ }
881
+ if (maxList > BUBBLE_LIST_MAX) {
882
+ const finer = cell * GRID_SHRINK;
883
+ const more = cells / (GRID_SHRINK * GRID_SHRINK * GRID_SHRINK) >
884
+ GRID_MAX_CELLS;
885
+ if (refinements < GRID_TRIES && !more) {
886
+ cell = finer;
887
+ refinements++;
888
+ continue;
889
+ }
890
+ // The smallest sphere of every full cell.
891
+ const smallest = new Int32Array(cells).fill(-1);
892
+ each((s, id) => {
893
+ if (counts[id] <= BUBBLE_LIST_MAX) {
894
+ return;
895
+ }
896
+ const m = smallest[id];
897
+ if (m < 0 || spheres[s * 4 + 3] < spheres[m * 4 + 3]) {
898
+ smallest[id] = s;
899
+ }
900
+ });
901
+ const drop = new Set();
902
+ for (const s of smallest) {
903
+ if (s >= 0) {
904
+ drop.add(s);
905
+ }
906
+ }
907
+ return { ok: false, drop: [...drop] };
908
+ }
909
+ const offsets = new Int32Array(cells);
910
+ let total = 0;
911
+ for (let id = 0; id < cells; id++) {
912
+ offsets[id] = total;
913
+ total += counts[id];
914
+ }
915
+ const cellTexH = Math.max(1, Math.ceil(cells / BUBBLE_TEX_W));
916
+ const cellData = new Float32Array(BUBBLE_TEX_W * cellTexH * 4);
917
+ for (let id = 0; id < cells; id++) {
918
+ cellData[id * 4] = offsets[id];
919
+ cellData[id * 4 + 1] = counts[id];
920
+ }
921
+ const indexTexH = Math.max(1, Math.ceil(total / 4 / BUBBLE_TEX_W));
922
+ const index = new Float32Array(BUBBLE_TEX_W * indexTexH * 4);
923
+ const fillAt = new Int32Array(cells);
924
+ each((s, id) => {
925
+ index[offsets[id] + fillAt[id]++] = s;
926
+ });
927
+ const sphereTexH = Math.max(1, Math.ceil(count / BUBBLE_TEX_W));
928
+ const sphereData = new Float32Array(BUBBLE_TEX_W * sphereTexH * 4);
929
+ sphereData.set(spheres);
930
+ return {
931
+ ok: true,
932
+ grid: {
933
+ spheres,
934
+ count,
935
+ origin: [lo[0], lo[1], lo[2]],
936
+ cell,
937
+ dims,
938
+ cellData,
939
+ cellTexH,
940
+ index,
941
+ indexTexH,
942
+ sphereData,
943
+ sphereTexH,
944
+ maxList,
945
+ refinements,
946
+ },
947
+ };
948
+ }
949
+ }
950
+ // How much a container blows the bubbles up at containment 1, as a share
951
+ // of what would close every gap: less leaves creases between them.
952
+ const CONTAIN_GROW = 0.3;
953
+ // The fill inside the shape: the gap it closes, per smallest bubble
954
+ // (minSize cell sizes): the gaps the placement leaves are about that
955
+ // wide.
956
+ const FILL_GAP = 1.4;
957
+ /**
958
+ * BubbleEffect's foam: the bubbles placed, blown up in a container, the
959
+ * grid the shader walks and the one it finds the borders with, and each
960
+ * bubble's drift.
961
+ */
962
+ let placed = null;
963
+ function buildFoam(a) {
964
+ // The placement does not depend on wobble or containment.
965
+ const key = JSON.stringify([a.shapeKey, a.fill]);
966
+ if (a.shapeKey === undefined || placed?.key !== key) {
967
+ if (!a.shape) {
968
+ throw new Error("buildFoam: no shape to place in");
969
+ }
970
+ placed = { key, fill: placeBubbles(a.shape, a.fill) };
971
+ }
972
+ // A copy: a worker gives the result's buffers away.
973
+ const fill = { ...placed.fill, spheres: placed.fill.spheres.slice() };
974
+ const cellSize = fill.cellSize;
975
+ // In a container the bubbles are blown up to fill it: r² grows by
976
+ // the same amount for all, which leaves every wall between two
977
+ // bubbles where it is and only pushes the foam's outside out, into
978
+ // the gaps and against the container. At 1 it covers a gap of the
979
+ // fill's smallest size next to the biggest bubble.
980
+ let spheres = fill.spheres;
981
+ let grow = 0;
982
+ if (a.containment > 0) {
983
+ let maxR = 0;
984
+ for (let i = 0; i < fill.count; i++) {
985
+ maxR = Math.max(maxR, fill.spheres[i * 4 + 3]);
986
+ }
987
+ const g = 0.5 * a.fill.minSize * cellSize;
988
+ const add = a.containment * CONTAIN_GROW * (2 * maxR * g + g * g);
989
+ spheres = fill.spheres.slice();
990
+ for (let i = 0; i < fill.count; i++) {
991
+ const r0 = spheres[i * 4 + 3];
992
+ const r1 = Math.sqrt(r0 * r0 + add);
993
+ spheres[i * 4 + 3] = r1;
994
+ grow = Math.max(grow, r1 - r0);
995
+ }
996
+ }
997
+ // The fill inside the shape: enough to close a gap of FILL_GAP
998
+ // smallest bubbles next to the biggest bubble. The grid lists each sphere as far
999
+ // as it can own a point with it.
1000
+ let fillG = 0;
1001
+ if (a.containment > 0) {
1002
+ let maxR = 0;
1003
+ for (let i = 0; i < spheres.length / 4; i++) {
1004
+ maxR = Math.max(maxR, spheres[i * 4 + 3]);
1005
+ }
1006
+ const h = FILL_GAP * Math.min(a.fill.minSize, 1) * cellSize;
1007
+ fillG = a.containment * (2 * maxR * h + h * h);
1008
+ }
1009
+ const grid = buildSphereGrid(spheres, a.wobble, cellSize, fillG);
1010
+ let edgeGrid = null;
1011
+ if (fillG > 0) {
1012
+ // The same spheres by their own radii: no list gets longer, so
1013
+ // none is left out and the indices match.
1014
+ const g = buildSphereGrid(grid.spheres, a.wobble, cellSize);
1015
+ if (g.dropped === 0) {
1016
+ edgeGrid = g;
1017
+ }
1018
+ }
1019
+ // Per bubble, the drift's frequencies and phases (as the shader's
1020
+ // hash of its index).
1021
+ const drift = new Float32Array(grid.count * 6);
1022
+ for (let i = 0; i < grid.count; i++) {
1023
+ const [x, y, z, w] = hash4(a.fill.seed, i, 977, 31);
1024
+ drift.set([0.6 + 0.8 * y, 0.6 + 0.8 * z, 0.6 + 0.8 * w, z, w, x], i * 6);
1025
+ }
1026
+ return { fill, grow, fillG, grid, edgeGrid, drift };
1027
+ }
1028
+ return {
1029
+ BUBBLE_TEX_W,
1030
+ BUBBLE_LIST_MAX,
1031
+ BUBBLE_MAX_COUNT,
1032
+ SPHERE_PROTRUDE,
1033
+ SPHERE_BULGE_Z,
1034
+ fillShape,
1035
+ hash4,
1036
+ sampleSd2,
1037
+ insideDistance,
1038
+ placeBubbles,
1039
+ buildSphereGrid,
1040
+ buildFoam,
1041
+ };
1042
+ }
1043
+ _a = bubbleKernel(), exports.BUBBLE_TEX_W = _a.BUBBLE_TEX_W, exports.BUBBLE_LIST_MAX = _a.BUBBLE_LIST_MAX, exports.BUBBLE_MAX_COUNT = _a.BUBBLE_MAX_COUNT, exports.SPHERE_PROTRUDE = _a.SPHERE_PROTRUDE, exports.SPHERE_BULGE_Z = _a.SPHERE_BULGE_Z, exports.fillShape = _a.fillShape, exports.hash4 = _a.hash4, exports.sampleSd2 = _a.sampleSd2, exports.insideDistance = _a.insideDistance, exports.placeBubbles = _a.placeBubbles, exports.buildSphereGrid = _a.buildSphereGrid, exports.buildFoam = _a.buildFoam;
1044
+ //# sourceMappingURL=_bubble-fill.js.map