Check out our latest project ✨ OpenChapter.io: free ebooks the way its meant to be 📖

Godot Volornoi Sweepline

An asset by Sinowa
The page banner background of a mountain and forest
Godot Volornoi Sweepline thumbnail image
Godot Volornoi Sweepline thumbnail image
Godot Volornoi Sweepline hero image

Quick Information

0 ratings
Godot Volornoi Sweepline icon image
Sinowa
Godot Volornoi Sweepline

A Godot 4.X add-on that generates and displays a Voronoi diagram using a port of my python implementation of Fortune's sweep line algorithm.V2 update:- Added Lloyd's Relaxation Algorithm(multi-threaded)- Fixed Final Known bugs

Supported Engine Version
4.2
Version String
2.2.0
License Version
MIT
Support Level
community
Modified Date
1 year ago
Git URL
Issue URL

Godot-Sweepline-Volornoi

A Godot 4.X addon that generates and displays a volornoi diagram using Fortone's sweepline algorithm. This project is a fun hobby project and I welcome you to fork it! :)

Example Results

README Image of diagram displayed through a shader README Image of a diagram displayed through Polygon2D

Features

Operation

You can generate a volornoi diagram through code using this plugin. See example.tscn for a runnable example.

  • To call the volornoi algorithm:
var point_list : Array[Vector2] = [Vector2(1,1), Vector2(3,1), Vector2(3,3), Vector2(2,2), Vector2(1,3)]
var voronoi : VoronoiSweepline = VoronoiSweepline.new()
voronoi.generate( point_list, [0, 4, 0, 4 ])
  • VoronoiSweepline.generate parameters:
    • point_list - The list of seed points that the algorithm uses. Must be in a Array[ Vector2 ] format.
    • sizebox - The area that the algorithm is iterating over. [left wall, right wall, floor, ceiling]. They CANNOT be negative and all points must be inside of the diagram. They cannot be on the border or errors may occur.
       (0,0)--floor----+   
         |             |
     left wall     right wall
         |             |
         +---ceiling-(x,y)
    
  • To use Lyod's relaxation algorithm
voronoi.relax()

Notes

  • Errors with polygon generation occur if there are points too close together due to computer floating point inprecision. Try to keep points at least 1 away from each other to minimize errors. Even further to ensure no errors occur.
  • To relax the diagram you have to generate the diagram first so there are cells to relax

Data Structures

Sweepline Algorithm

class VoronoiSweepline:
    func _init() -> void
    func generate(point_list : Array[Vector2], sizebox : Array) -> void
    func relax() -> void
    func process_cell_chunk( chunk : Array, start_idx : int, output_lst : Array[Vector2]) -> void
    func calc_centroid(pointlist : Array) -> Vector2

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Acknowledgments

A Godot 4.X add-on that generates and displays a Voronoi diagram using a port of my python implementation of Fortune's sweep line algorithm.
V2 update:
- Added Lloyd's Relaxation Algorithm(multi-threaded)
- Fixed Final Known bugs

Reviews

0 ratings

Your Rating

Headline must be at least 3 characters but not more than 50
Review must be at least 5 characters but not more than 500
Please sign in to add a review

Quick Information

0 ratings
Godot Volornoi Sweepline icon image
Sinowa
Godot Volornoi Sweepline

A Godot 4.X add-on that generates and displays a Voronoi diagram using a port of my python implementation of Fortune's sweep line algorithm.V2 update:- Added Lloyd's Relaxation Algorithm(multi-threaded)- Fixed Final Known bugs

Supported Engine Version
4.2
Version String
2.2.0
License Version
MIT
Support Level
community
Modified Date
1 year ago
Git URL
Issue URL

Open Source

Released under the AGPLv3 license

Plug and Play

Browse assets directly from Godot

Community Driven

Created by developers for developers