Poisson Disk Sampler

by decapitated

6

Poisson Disk Sampler

A "Fast Poisson Disk Sampling" Godot plugin

Godot Asset Library

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

Version

1.0.1

Engine

4.2

Category

2D Tools

Download

Version1.0.1
Download

Support

If you need help or have questions about this plugin, please contact the author.

Contact Author