Skip to content

Commit

Permalink
[Release] v. 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
andywiecko committed Oct 26, 2021
1 parent 05f06ad commit 22118a5
Show file tree
Hide file tree
Showing 23 changed files with 1,053 additions and 62 deletions.
60 changes: 0 additions & 60 deletions .gitignore

This file was deleted.

7 changes: 7 additions & 0 deletions CHANGELOG.md
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
7 changes: 7 additions & 0 deletions CHANGELOG.md.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Documentation~/burst-benchmark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Documentation~/nyan-cat-with-refinement.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Documentation~/nyan-cat-without-refinement.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Documentation~/nyan-cat.png
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.
7 changes: 7 additions & 0 deletions LICENSE.md.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

106 changes: 104 additions & 2 deletions README.md
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:

![nyan-cat](Documentation~/nyan-cat.png)

The result *without* mesh refinement (Delaunay triangulation):

![nyan-cat-without-refinement](Documentation~/nyan-cat-without-refinement.png)

The result *with* mesh refinement:

![nyan-cat-with-refinement](Documentation~/nyan-cat-with-refinement.png)

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.

![Burst Triangulator benchmark](Documentation~/burst-benchmark.png "Burst Triangulator benchmark")

## 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
7 changes: 7 additions & 0 deletions README.md.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Runtime.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 22118a5

Please sign in to comment.