Skip to content

Decapitated/Godot-Poisson-Disk-Sampler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Poisson Disk Sampler

A "Fast Poisson Disk Sampling" Godot plugin

Godot Asset Library

Poisson Animated FillPoissonDiskSampler2D Custom InspectorPoissonDiskSampler2D Example Scene


I created this after trying [udit's implementation](https://github.com/udit/poisson-disc-sampling). For whatever reason it didn't work for me, and wanted to try doing it myself. This one aims to improve by abstracting the way points are validated, as well as possibly adding more dimensions - as stated in Robert's paper.

Usage

How to generate points for different shapes:

Polygon

var poisson_points = PoissonDiskSampler.generate_points(
        get_polygon_rect(polygon), # Polygon bounding rect.
        min_dist,
        max_attempts,
        _is_point_in_polygon.bind(polygon))

func _is_point_in_polygon(point: Vector2, polygon: Polygon2D) -> bool:
    return Geometry2D.is_point_in_polygon(point, polygon.polygon)

Circle

var circle_rect = Rect2(Vector2(0.0, 0.0), Vector2(1000.0, 1000.0))
var poisson_points = PoissonDiskSampler.generate_points(
        circle_rect,
        min_dist,
        max_attempts,
        _is_point_in_circle.bind(circle_rect))

func _is_point_in_circle(point: Vector2, rect: Rect2) -> bool:
    var radius = rect.size.x / 2.0
    return point.distance_squared_to(rect.size / 2.0) <= radius * radius

To-Do

  • Right now for each point, we loop over all added points to check if it is valid. You're supposed to only check nearby points. Need to get that working.

Citations

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published