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