forked from andywiecko/BurstTriangulator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
05f06ad
commit 22118a5
Showing
23 changed files
with
1,053 additions
and
62 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Change log | ||
|
||
## [1.0.0] – 2021-10-26 | ||
|
||
### Features | ||
|
||
- Initial release version |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,104 @@ | ||
# Triangulator | ||
2d Delaunay triangulation with mesh refinement for Unity | ||
# Burst Triangulator | ||
|
||
A single-file package which provides simple Delaunay triangulation of the given set of points (`float2`) with mesh refinement. | ||
Implemented triangulation is based on [Bowyer–Watson algorithm][bowyerwatson] and refinement on [Ruppert's algorithm][rupperts]. | ||
|
||
## Getting started | ||
|
||
To use the package choose one of the following: | ||
|
||
- Clone or download this repository and then select `package.json` using Package Manager (`Window/Package Manager`). | ||
|
||
- Put the file [`Runtime/Triangulator.cs`](Runtime/Triangulator.cs) somewhere in your project to use this independently. | ||
|
||
- Use package manager via git install: `https://github.com/andywiecko/BurstTriangulator/`. | ||
|
||
## Usage | ||
|
||
Below one can find example usage of the `Triangulator` with input set as four | ||
points that form the unit square: | ||
|
||
```csharp | ||
var positions = new[] | ||
{ | ||
math.float2(0, 0), | ||
math.float2(1, 0), | ||
math.float2(1, 1), | ||
math.float2(0, 1) | ||
}; | ||
|
||
using var triangulator = new Triangulator(capacity: 1024, Allocator.Persistent); | ||
using var inputPositions = new NativeArray<float2>(positions, Allocator.Persistent); | ||
|
||
triangulator.Schedule(inputPositions.AsReadOnly(), default).Complete(); | ||
|
||
var outputTriangles = triangulator.Triangles; | ||
var outputPositions = triangulator.Positions; | ||
``` | ||
|
||
The result of the triangulation procedure will depend on selected settings. | ||
There are a few settings of the triangulation, shortly described below: | ||
|
||
```csharp | ||
var settings = triangulator.Settings; | ||
|
||
// Triangle is considered as bad if any of its angles is smaller than MinimumAngle. Note: radians. | ||
settings.MinimumAngle = math.radians(33); | ||
// Triangle is not considered as bad if its area is smaller than MinimumArea. | ||
settings.MinimumArea = 0.015f | ||
// Triangle is considered as bad if its area is greater than MaximumArea. | ||
settings.MaximumArea = 0.5f; | ||
// If true, refines mesh using Ruppert's algorithm. | ||
settings.RefineMesh = true; | ||
// Batch count used in parallel job. | ||
settings.BatchCount = 64; | ||
``` | ||
|
||
## Example result | ||
|
||
The boundary of "Nyan Cat" was used as a test specimen: | ||
|
||
 | ||
|
||
The result *without* mesh refinement (Delaunay triangulation): | ||
|
||
 | ||
|
||
The result *with* mesh refinement: | ||
|
||
 | ||
|
||
Note: to obtain the boundary from a texture, the `UnityEngine.PolygonCollider` was used. | ||
Generating the image boundary is certainly a separate task and is not considered in the project. | ||
|
||
## Benchmark | ||
|
||
The package uses `Burst` compiler, which produces highly optimized native code using LLVM. | ||
Below one can see a log-log plot of elapsed time as a function of the final triangles count after mesh refinement. | ||
Using Burst can provide more or less two order of magnitude faster computation. | ||
|
||
 | ||
|
||
## Dependencies | ||
|
||
- [`Unity.Burst`](https://docs.unity3d.com/Packages/[email protected]/manual/index.html) | ||
- [`Unity.Mathematics`](https://docs.unity3d.com/Packages/[email protected]/manual/index.html) | ||
- [`Unity.Collections`](https://docs.unity3d.com/Packages/[email protected]/manual/index.html) | ||
- [`Unity.Jobs`](https://docs.unity3d.com/Manual/JobSystem.html) | ||
|
||
## TODO | ||
|
||
- Use bounding volume (or kd) tree to speed up the computation. | ||
- Add option of preserving the external edges of input points. | ||
- Add support for "holes". | ||
- Consider better parallelism. | ||
- Do some optimization with respect to SIMD architecture. | ||
- CI/CD setup. | ||
- Add more sophisticated tests. | ||
|
||
## Contributors | ||
|
||
- [Andrzej Więckowski, Ph.D](https://andywiecko.github.io/). | ||
|
||
[bowyerwatson]: https://en.wikipedia.org/wiki/Bowyer%E2%80%93Watson_algorithm | ||
[rupperts]: https://en.wikipedia.org/wiki/Delaunay_refinement#Ruppert's_algorithm |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.