Holes and boundaries
Restoring boundaries
The package also provides an option for restoring boundaries. In addition to setting the RestoreBoundary
property, one needs to provide edge constraints to restore the boundaries.
using var constraintEdges = new NativeArray<int>(..., Allocator.Persistent);
using var positions = new NativeArray<double2>(..., Allocator.Persistent);
using var triangulator = new Triangulator(Allocator.Persistent)
{
Input = {
Positions = positions,
ConstraintEdges = constraintEdges,
},
Settings = {
RestoreBoundary = true,
}
};
triangulator.Run();
var triangles = triangulator.Output.Triangles;
Holes supports
The package also provides an option for creating holes.
In addition to setting the Input.ConstraintEdges
, a user needs to provide positions of the holes in the same space as the Input.Positions
. Enabling the RestoreBoundary
option is not mandatory; holes could be introduced independently of preserving the boundaries.
using var constraintEdges = new NativeArray<int>(..., Allocator.Persistent);
using var holes = new NativeArray<double2>(..., Allocator.Persistent);
using var positions = new NativeArray<double2>(..., Allocator.Persistent);
using var triangulator = new Triangulator(Allocator.Persistent)
{
Input = {
Positions = positions,
ConstraintEdges = constraintEdges,
HoleSeeds = holes,
},
Settings = {
RestoreBoundary = true, // optional can be set independently
}
};
triangulator.Run();
var triangles = triangulator.Output.Triangles;
Auto holes and boundary
The package also provides automatic hole detection and restoring boundary. If one sets Settings.AutoHolesAndBoundary
to true
, then holes will be created automatically depending on the provided constraints.
using var positions = new NativeArray<double2>(..., Allocator.Persistent);
using var constraintEdges = new NativeArray<int>(..., Allocator.Persistent);
using var triangulator = new Triangulator(Allocator.Persistent)
{
Input = {
Positions = positions,
ConstraintEdges = constraintEdges,
},
Settings = { AutoHolesAndBoundary = true, },
};
triangulator.Run();
var triangles = triangulator.Output.Triangles;
Warning
The current implementation of AutoHolesAndBoundary
detects only 1-level islands.
It will not detect holes in solid meshes inside other holes.