{"id":13663854,"url":"https://github.com/OskarSigvardsson/unity-delaunay","last_synced_at":"2025-04-25T18:31:16.332Z","repository":{"id":50310268,"uuid":"122244015","full_name":"OskarSigvardsson/unity-delaunay","owner":"OskarSigvardsson","description":"A Delaunay/Voronoi library for Unity, and a simple destruction effect","archived":false,"fork":false,"pushed_at":"2023-08-28T19:03:44.000Z","size":37736,"stargazers_count":800,"open_issues_count":3,"forks_count":80,"subscribers_count":31,"default_branch":"master","last_synced_at":"2024-11-10T20:38:34.134Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OskarSigvardsson.png","metadata":{"files":{"readme":"README.org","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-02-20T19:18:15.000Z","updated_at":"2024-11-06T17:07:59.000Z","dependencies_parsed_at":"2024-08-02T05:29:56.229Z","dependency_job_id":null,"html_url":"https://github.com/OskarSigvardsson/unity-delaunay","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OskarSigvardsson%2Funity-delaunay","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OskarSigvardsson%2Funity-delaunay/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OskarSigvardsson%2Funity-delaunay/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OskarSigvardsson%2Funity-delaunay/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OskarSigvardsson","download_url":"https://codeload.github.com/OskarSigvardsson/unity-delaunay/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250872034,"owners_count":21500755,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T05:02:39.040Z","updated_at":"2025-04-25T18:31:16.290Z","avatar_url":"https://github.com/OskarSigvardsson.png","language":"C#","funding_links":[],"categories":["C\\#","Open Source Repositories","C#","Mesh","Open Source Packages","Game Development"],"sub_categories":["Effect and Shaders","Unity Engine: Resources"],"readme":"\n* Voronoi destruction effect\nI was interested in implementing some algorithms for generating Delaunay\ntriangulations and Voronoi diagrams, and since it's basically obligatory for\nanyone making Voronoi diagram libraries to make a destruction effect, this is\nmine!\n\nThe code is written in C#, and made for the Unity engine. If you want just the\nDelaunay/Voronoi parts, they're in the Assets/Plugins/Delaunay folder. They're\nnot quite as polished as I would like, but I would say that they're suitable for\nproduction. If you use it and have any problems, let me know! In fact, if you\nuse it at all, I'd really appreciate hearing about it!\n\n** Demo\n[[https://thumbs.gfycat.com/FoolhardyNegligibleGreyhounddog-size_restricted.gif]]\n\n[[https://youtu.be/f3T5jtsokz8][Higher res version]]\n** Implementation details\nI'm generating the Delaunay triangulation using the incremental algorithm\n(Bowyer-Watson), and generating the voronoi diagram from the delaunay\ntriangulation. You can also clip the voronoi diagram to any convex shape (it\nuses Sutherland-Hodgman clipping, adapted to voronoi diagrams).\n\nThe fact that you can clip to any convex shape is neat, because it means you can\n\"recursively\" generate voronoi diagrams, so you can shatter already generated\nvoronoi shards.\n\nAll the \"generator\" classes (the delaunay generator, the voronoi generator, and\nthe voronoi clipper) are designed in such a way as to not generate any garbage\nif they are reused (though I'm currently not doing that in the example code). If\nyou were to do this in a real game, it would be suitable to run the generators\non background threads, though they're certainly performant enough to run in real\ntime in a single-threaded environment.\n\nI was going to develop this a bit further, but the limiting factor in this kind\nof destruction effect is the physics. If you generate these kinds of shards and\nlet them pile up, the physics engine basically implodes. Given that that was the\nlimitation, I sort-of lost interest in the project. As such, the\nnon-Delaunay/Voronoi parts of the code are super-unoptimized and kind of a mess\n:)\n\n** Bowyer-Watson\nIt was an interesting experience to implement Bowyer-Watson, because I realized\nthat virtually every implementation I could find online was wrong. The algorithm\ngenerates a Delaunay triangulation by first creating one big \"container\"\ntriangle, and then iteratively adding sites to it splitting the big triangle\ninto smaller triangles. However, the algorithm is only accurate if two of the\nvertices of the containing triangle are outside every circumcircle formed by any\nthree points in the set points (the third vertex must be a \"corner vertex\" of\nsorts). Many implementations solve this by placing the vertices of the corners\nsome large distance away, or by using some formula that guarantees that the\ntriangle completely surrounds all the points (such as [[https://github.com/axelboc/voronoi-delaunay/blob/master/app/lib/voronoi.js#L130][here]] or [[https://github.com/ariqchowdhury/bowyer-watson/blob/master/bowyer_watson.go#L55][here]]).\n\nThis is a mistake. It's not enough that the \"super\" triangle surrounds all the\npoints, you have to guarantee that the two vertices are outside every possible\ncircumcircle of any three points, and these circumcircles can very easily become\nhuge. In fact, if three points are collinear, the \"circumcircle\" is essentially\nan infinite half-plane. Even if no three points are collinear, if they're even\nclose to collinear, the radius of the circle is *massive*. If you don't account\nfor this, the delaunay triangulation will not be correct. One easy way to spot\nincorrect implementations is that the the convex hull will not be part of the\ntriangulation, and the convex hull is always part of the Delaunay triangulation.\nVirtually every implemention of this algorithm i could find online made this\nmistake, and you can often see it in the visualizations ([[https://cdn.rawgit.com/axelboc/voronoi-delaunay/v2.1/index.htm][here]], for instance).\n\nTo do it right, you have to treat the vertices of the surrounding triangle as\n\"symbolic\" points. One way of thinking about them is that they're sort of\n\"infinitely\" far away, but it's more correct to say that they're points with\nspecial rules for how they're compared to the rest of the points. [[http://www.cs.uu.nl/geobook/interpolation.pdf][Computational\nGeometry: Algorithms and Applications]] describes this approach, but even they are\nwrong in one small detail: the test on the bottom on page 204 is wrong.\n\nThis experience has lead me to belive that using the incremental approach to\ngenerate Delaunay triangulations and Voronoi diagrams is a bad way to do it. It\nseems simpler to implement than other versions, but this subtlety with the\ncontaining triangle the fact that you have to construct an intricate tree\nstructure makes the algorithm more complex and easier to get wrong than\nsomething like Quickhull or Fortune's sweep-line algorithm. It's also usually a\nbit slower. Still, it was a fun thing to implement, and having powered through\nit, you end up with a pretty stable and robust Delaunay/Voronoi calculator\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FOskarSigvardsson%2Funity-delaunay","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FOskarSigvardsson%2Funity-delaunay","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FOskarSigvardsson%2Funity-delaunay/lists"}