### Optional fixed-point dependency in manifest.json Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/getting-started.md Adds the optional fixed-point arithmetic package via Git URL. Not available on OpenUPM, so manual installation is recommended. ```json "dependencies": { "com.danielmansson.mathematics.fixedpoint": "https://github.com/andywiecko/Unity.Mathematics.FixedPoint.git#d44836cab621f299d6d1bfa275daa437aafc739b", ... ``` -------------------------------- ### Git dependency entry for BurstTriangulator Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/getting-started.md Installs the package via Git URL in manifest.json. By default, installs the latest commit from the main branch; specify a tag or commit with a hash suffix. ```json "dependencies": { "com.andywiecko.burst.triangulator": "https://github.com/andywiecko/BurstTriangulator.git", ... ``` -------------------------------- ### OpenUPM scoped registry configuration in manifest.json Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/getting-started.md Adds the OpenUPM scoped registry to manifest.json for installing the package via OpenUPM. Required before adding the dependency. ```json "scopedRegistries": [ { "name": "OpenUPM", "url": "https://package.openupm.com/", "scopes": [ "com.andywiecko" ] } ] ``` -------------------------------- ### OpenUPM dependency entry for BurstTriangulator Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/getting-started.md Specifies the desired version of the package in the dependencies section of manifest.json. Use after configuring the scoped registry. ```json "dependencies": { "com.andywiecko.burst.triangulator": "3.10.0", ... ``` -------------------------------- ### Triangulator.Run with ValidateInput Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/advanced/input-validation.md Demonstrates how to enable input validation and run the triangulation procedure. The example shows how to set ValidateInput to true and check the output status for errors. ```APIDOC ## Triangulator.Run with ValidateInput ### Description Demonstrates how to enable input validation and run the triangulation procedure. The example shows how to set ValidateInput to true and check the output status for errors. ### Method Run ### Endpoint Triangulator.Run() ### Parameters #### Settings - **ValidateInput** (bool) - Required - When set to true, the input data and settings are validated before triangulation. ### Response #### Output - **Status** (Status) - The status of the triangulation, can be used to catch validation errors. ### Request Example ```csharp using var triangulator = new Triangulator(Allocator.Persistent) { Input = { ... }, Settings = { ValidateInput = true }, }; triangulator.Run(); var status = triangulator.Output.Status.Value; ``` ``` -------------------------------- ### Perform classic Delaunay triangulation with Triangulator Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/examples/triangulation.md Creates a Triangulator with input positions and runs it to produce the output triangles. Classic triangulation produces the convex hull of the input; see the boundaries example to restore the boundary. ```csharp using var positions = new NativeArray(..., Allocator.Persistent); using var triangulator = new Triangulator(Allocator.Persistent) { Input = { Positions = positions } }; triangulator.Run(); var triangles = triangulator.Output.Triangles; ``` -------------------------------- ### Triangulate unit square with Triangulator Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/examples/index.md Creates a NativeArray of four points forming a unit square, runs the Triangulator on the main thread, and retrieves the output triangles. The Run() method executes synchronously; for jobs, use Schedule(dependencies). ```csharp using var positions = new NativeArray(new double2[] { new(0, 0), new(1, 0), new(1, 1), new(0, 1), }, Allocator.Persistent); using var triangulator = new Triangulator(capacity: 1024, Allocator.Persistent) { Input = { Positions = positions } }; triangulator.Run(); var triangles = triangulator.Output.Triangles; ``` -------------------------------- ### DynamicInsertPoint usage example Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/advanced/dynamic-triangulation.md Shows how to set up input/output buffers, triangulate, and insert a point into triangle 42 using barycentric coordinates. The point must lie inside the original triangulation domain; all bar coordinates must be in (0,1) and sum to 1. The method requires the triangle index and barycentric coordinates, and does not include acceleration structures for point lookup. ```csharp var t = new UnsafeTriangulator(); using var positions = new NativeArray(..., Allocator.Persistent); using var constraints = new NativeArray(..., Allocator.Persistent); var input = new NativeInputData { Positions = positions, ConstraintEdges = constraints }; using var outputPositions = new NativeList(Allocator.Persistent); using var triangles = new NativeList(Allocator.Persistent); using var halfedges = new NativeList(Allocator.Persistent); using var constrainedHalfedges = new NativeList(Allocator.Persistent); var output = new NativeOutputData { Positions = outputPositions, Triangles = triangles, Halfedges = halfedges, ConstrainedHalfedges = constrainedHalfedges }; t.Triangulate(input, output, args: Args.Default(autoHolesAndBoundary: true), Allocator.Persistent); // Insert a new point in triangle with index 42 at the center (barycentric coordinates: [⅓, ⅓, ⅓]). t.DynamicInsertPoint(output, tId: 42, bar: 1f / 3, allocator: Allocator.Persistent); ``` -------------------------------- ### Split halfedges with DynamicSplitHalfedge Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/advanced/dynamic-triangulation.md Splits a halfedge by inserting a point at a position interpolated between its start and end points using the alpha parameter. Preserves the constrained state of the halfedge. The example iteratively splits random halfedges after triangulating input data. ```csharp var t = new UnsafeTriangulator(); using var positions = new NativeArray(..., Allocator.Persistent); using var constraints = new NativeArray(..., Allocator.Persistent); var input = new NativeInputData { Positions = positions, ConstraintEdges = constraints }; using var outputPositions = new NativeList(Allocator.Persistent); using var triangles = new NativeList(Allocator.Persistent); using var halfedges = new NativeList(Allocator.Persistent); using var constrainedHalfedges = new NativeList(Allocator.Persistent); var output = new NativeOutputData { Positions = outputPositions, Triangles = triangles, Halfedges = halfedges, ConstrainedHalfedges = constrainedHalfedges }; t.Triangulate(input, output, args: Args.Default(autoHolesAndBoundary: true), Allocator.Persistent); // Iteratively split random halfedges. var random = new Unity.Mathematics.Random(seed: 42); for(int i = 0; i < 32; i++) { t.DynamicInsertPoint(output, he: random.NextInt(0, triangles.Length), alpha: 0.5f, allocator: Allocator.Persistent); } ``` -------------------------------- ### Configure RefineMesh and RefinementThresholds in C# Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/examples/mesh-refinement.md Sets RefineMesh to true and specifies Area and Angle thresholds for mesh refinement. The example creates a Triangulator with input positions, runs it, and retrieves output triangles and positions. Refinement works for both constrained and non-constrained triangulation. ```csharp using var inputPositions = new NativeArray(..., Allocator.Persistent); using var triangulator = new Triangulator(Allocator.Persistent) { Input = { Positions = inputPositions }, Settings = { RefineMesh = true, RefinementThresholds = { Area = 1f, Angle = math.radians(20f) }, } }; triangulator.Run(); var triangles = triangulator.Output.Triangles; var positions = triangulator.Output.Positions; ``` -------------------------------- ### Retriangulate a Mesh with settings and axis input Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/utilities.md Retriangulates a Unity Mesh using the `Retriangulate` extension method. Supports non-uniform meshes, including windmill-like connections. The example sets `AutoHolesAndBoundary`, `RefineMesh`, and refinement thresholds, with `Axis.XZ` and `UVMap.Planar`. Refer to the API documentation for additional settings. ```csharp mesh.Retriangulate( settings: new() { AutoHolesAndBoundary = true, RefineMesh = true, RefinementThresholds = { Angle = 0, Area = 1e-2f } }, axisInput: Axis.XZ, uvMap: UVMap.Planar, ); ``` -------------------------------- ### Equivalent managed Triangulator approach Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/advanced/unsafe-triangulator.md Managed counterpart to the unsafe example. Uses Triangulator with Input.Positions and Output.Triangles. ```csharp using var positions = new NativeArray(..., Allocator.Persistent); using var triangulator = new Triangulator(Allocator.Persistent) { Input = { Positions = positions } }; triangulator.Run(); var triangles = triangulator.Output.Triangles; ``` -------------------------------- ### InsertSubMesh: combine meshes by inserting a sub-mesh Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/utilities.md Combines meshes by inserting a sub-mesh into the main mesh. Triangle indices are adjusted automatically. The example creates native lists for positions and triangles, then inserts a sub-mesh defined by subpositions and subtriangles. ```csharp using var positions = new NativeList(..., Allocator); using var triangles = new NativeList(..., Allocator); var subpositions = new float2[] { math.float2(0, 0), math.float2(1, 0), math.float2(1, 1) }; var subtriangles = new[] { 0, 1, 2 }; Utilities.InsertSubMesh(positions, triangles, subpositions, subtriangles); ``` -------------------------------- ### Utilities.GenerateHalfedges Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/utilities.md Generates halfedges based on the given triangles. The provided allocator is used for temporary data allocation. Useful when you have mesh data but need to use halfedges, for example, when iterating through the mesh. ```APIDOC ## Utilities.GenerateHalfedges ### Description Generates halfedges based on the given triangles. The provided `allocator` is used for temporary data allocation. Useful when you have mesh data but need to use halfedges, for example, when iterating through the mesh. ### Method `Utilities.GenerateHalfedges` ### Parameters - `halfedges` (int array) - Required - The output array to store the generated halfedges. - `triangles` (int array) - Required - The input triangle indices. - `allocator` (Allocator) - Required - The allocator used for temporary data allocation. ### Request Example ```csharp Mesh mesh = ... var triangles = mesh.triangles; var halfedges = new int[triangles.Length]; Utilities.GenerateHalfedges(halfdeges, triangles, Allocator.Persistent); ``` ``` -------------------------------- ### Modify Args with With() method Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/advanced/unsafe-triangulator.md Use the With method to return a new Args instance with selected parameters replaced, since Args is a readonly struct and cannot be modified in place. The example shows creating default args then setting refineMesh to true. ```csharp var args = Args.Default(); args = args.With(refineMesh: true); ``` -------------------------------- ### DynamicRemoveBulkPoint usage example Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/advanced/dynamic-triangulation.md Removes a bulk point (non-boundary) by its index pId and re-triangulates the affected region. Requires output and allocator parameters in addition to pId. The example uses UnsafeTriangulator with NativeInputData and NativeOutputData, then calls DynamicRemoveBulkPoint with pId: 8. ```csharp using var inputPositions = new NativeArray(..., Allocator.Persistent); using var outputPositions = new NativeList(Allocator.Persistent); using var triangles = new NativeList(Allocator.Persistent); using var constrainedHalfedges = new NativeList(Allocator.Persistent); using var halfedges = new NativeList(Allocator.Persistent); var t = new UnsafeTriangulator(); var input = new NativeInputData { Positions = inputPositions }; var output = new NativeOutputData { Positions = outputPositions, Triangles = triangles, ConstrainedHalfedges = constrainedHalfedges, Halfedges = halfedges, }; t.Triangulate(input, output, args: Args.Default(), allocator: Allocator.Persistent); t.DynamicRemoveBulkPoint(output, pId: 8, allocator: Allocator.Persistent); ``` -------------------------------- ### Check triangulation status for errors Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/examples/index.md After running triangulation, checks the Output.Status.Value against Status.OK to detect failures. The Status enum can be used to handle various error codes; see API documentation for other values. ```csharp status = triangulator.Output.Status.Value; if (status != Status.OK) // ERROR! { return; } ``` -------------------------------- ### Use RetriangulateMeshJob for advanced customization Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/utilities.md Executes a `RetriangulateMeshJob` for advanced retriangulation. The job can run on the main thread, be scheduled in the Job System, or run inside another job. All output containers must be allocated before running; the example uses `NativeList` and `Mesh.AcquireReadOnlyMeshData`. ```csharp using var outputPositions = new NativeList(Allocator.Persistent); using var outputTriangles = new NativeList(Allocator.Persistent); using var meshDataArray = Mesh.AcquireReadOnlyMeshData(mesh); var meshData = meshDataArray[0]; new RetriangulateMeshJob(meshData, outputPositions, outputTriangles, args: Args.Default(autoHolesAndBoundary: true), axisInput: Axis.XY ).Schedule(dependencies) // ... dependencies.Complete(); ``` -------------------------------- ### Catch errors in the job with Status check Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/advanced/input-jobs.md Example of a Burst-compiled job that checks the triangulation status and returns early if it is not OK. The job is scheduled after the triangulation, using the same dependencies. ```csharp [BurstCompile] private struct Job : IJob { NativeReference.ReadOnly status; public Job(Triangulator triangulator) { status = triangulator.Output.Status.AsReadOnly(); } public void Execute() { if (status != Status.OK) { return; } ... } } ... var dependencies = default(JobHandle); dependencies = triangulator.Schedule(dependencies); dependencies = new Job(triangulator).Schedule(dependencies); ... ``` -------------------------------- ### DynamicSplitHalfedge Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/advanced/dynamic-triangulation.md Splits a specified halfedge by inserting a point at a position determined by linear interpolation between the start and end points. This method preserves the constrained state of the halfedge, marking the resulting sub-segments as constrained if the original was constrained. ```APIDOC ## DynamicSplitHalfedge ### Description Splits a specified halfedge by inserting a point at a position determined by linear interpolation between the start and end points of the halfedge. This method preserves the constrained state of the halfedge, meaning that if the specified halfedge is constrained, the two resulting sub-segments will also be marked as constrained. ### Method DynamicSplitHalfedge ### Parameters - **he** (int) - Required - The index of the halfedge to split. - **alpha** (float) - Required - The interpolation parameter for positioning the new point between the start and end points of the halfedge, where p = (1 - alpha) * start + alpha * end. ### Example ```csharp var t = new UnsafeTriangulator(); using var positions = new NativeArray(..., Allocator.Persistent); using var constraints = new NativeArray(..., Allocator.Persistent); var input = new NativeInputData { Positions = positions, ConstraintEdges = constraints }; using var outputPositions = new NativeList(Allocator.Persistent); using var triangles = new NativeList(Allocator.Persistent); using var halfedges = new NativeList(Allocator.Persistent); using var constrainedHalfedges = new NativeList(Allocator.Persistent); var output = new NativeOutputData { Positions = outputPositions, Triangles = triangles, Halfedges = halfedges, ConstrainedHalfedges = constrainedHalfedges }; t.Triangulate(input, output, args: Args.Default(autoHolesAndBoundary: true), Allocator.Persistent); // Iteratively split random halfedges. var random = new Unity.Mathematics.Random(seed: 42); for(int i = 0; i < 32; i++) { t.DynamicInsertPoint(output, he: random.NextInt(0, triangles.Length), alpha: 0.5f, allocator: Allocator.Persistent); } ``` ``` -------------------------------- ### ConstrainEdge extension with UnsafeTriangulator Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/advanced/unsafe-triangulator.md Constrains edge (pi, pj) during dynamic triangulation. Restricted to bulk mesh; the edge must not intersect any holes. Optional ignoreForPlantingSeeds ignores corresponding halfedges during seed planting. Example shows triangulating then constraining edge (0,1). ```csharp using var inputPositions = new NativeArray(..., Allocator.Persistent); var output = new NativeOutputData { Positions = inputPositions, }; using var status = new NativeReference(Status.OK, Allocator.Persistent); using var outputPositions = new NativeList(Allocator.Persistent); using var triangles = new NativeList(Allocator.Persistent); using var halfedges = new NativeList(Allocator.Persistent); using var constrainedHalfedges = new NativeList(Allocator.Persistent); using var ignoredHalfedgesForPlantingSeeds = new NativeList(Allocator.Persistent); var output = new NativeOutputData { Status = status, Positions = outputPositions, Triangles = triangles, Halfedges = halfedges, ConstrainedHalfedges = constrainedHalfedges, IgnoredHalfedgesForPlantingSeeds = ignoredHalfedgesForPlantingSeeds, }; var t = new UnsafeTriangulator(); t.Triangulate(input, output, args: Args.Default(), Allocator.Persistent); t.ConstrainEdge(output, pi: 0, pj: 1, allocator: Allocator.Persistent, ignoreForPlantingSeeds: true); ``` -------------------------------- ### Apply AlphaShapeFilter after triangulation with UnsafeTriangulator Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/advanced/unsafe-triangulator.md Use the AlphaShapeFilter extension to apply an alpha-shape filter to triangulated data, useful when you need to control when filtering is applied (e.g., after refinement). Specify the alpha value using precision type T, except when T = int, which requires float alpha. This example sets protectPoints, preventWindmills, and protectConstraints to true. ```csharp using var positions = new NativeArray(..., Allocator.Persistent); using var constraints = new NativeArray(..., Allocator.Persistent); var input = new NativeInputData { Positions = positions, ConstraintEdges = constraints, }; using var outputPositions = new NativeList(Allocator.Persistent); using var triangles = new NativeList(Allocator.Persistent); using var halfedges = new NativeList(Allocator.Persistent); using var constrainedHalfedges = new NativeList(Allocator.Persistent); var output = new NativeOutputData { Positions = outputPositions, Triangles = triangles, Halfedges = halfedges, ConstrainedHalfedges = constrainedHalfedges, }; var t = new UnsafeTriangulator(); t.Triangulate(input, output, Args.Default(), Allocator.Persistent); t.AlphaShapeFilter(output, Allocator.Persistent, alpha, protectPoints: true, preventWindmills: true, protectConstraints: true); ``` -------------------------------- ### Triangulate unit box with Triangulator Source: https://github.com/andywiecko/bursttriangulator/blob/main/README.md Creates a NativeArray of positions for a unit box, runs the triangulator, and retrieves the output triangles. Requires the BurstTriangulator namespace and Unity.Collections. ```csharp using var positions = new NativeArray(new[] { new(0, 0), new(1, 0), new(1, 1), new(0, 1) }, Allocator.Persistent); using var triangulator = new Triangulator(Allocator.Persistent) { Input = { Positions = positions } }; triangulator.Run(); var triangles = triangulator.Output.Triangles; ``` -------------------------------- ### Set Preprocessor to COM Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/advanced/preprocessor.md Assigns the COM preprocessor to the triangulator settings to transform input into normalized local space ([-1, 1] box). Use this before triangulation to improve handling of non-uniform data. ```csharp triangulator.Settings.Preprocessor = Triangulator.Preprocessor.COM; ``` -------------------------------- ### Create Args with Args.Default() Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/advanced/unsafe-triangulator.md Use Args.Default() to create a LowLevel.Unsafe.Args instance with default values, passing named parameters to override specific settings. This is required because Unity's C# version restriction prevents default field/property values in structs. ```csharp var args = Args.Default(refineMesh: true); ``` -------------------------------- ### Add using directive for BurstTriangulator Source: https://github.com/andywiecko/bursttriangulator/blob/main/README.md Add this using directive to access the BurstTriangulator namespace in your code. ```csharp using andywiecko.BurstTriangulator; ``` -------------------------------- ### Utilities.BoundingBox for float2 positions Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/utilities.md Returns the axis-aligned bounding box for a collection of points. Supports all position types (float2/int2/double2/fp2). The result is a tuple (min, max). ```csharp var positions = new float2[]{ ... }; var (min, max) = Utilities.BoundingBox(positions); ``` -------------------------------- ### Generate input in the job with deferred arrays Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/advanced/input-jobs.md Shows how to create input for triangulation inside a job pipeline using deferred arrays (AsDeferredJobArray). The triangulator is scheduled after a GenerateInputJob that fills the arrays. ```csharp using var positions = new NativeList(64, Allocator.Persistent); using var constraints = new NativeList(64, Allocator.Persistent); using var holes = new NativeList(64, Allocator.Persistent); using var triangulator = new Triangulator(64, Allocator.Persistent) { Input = { Positions = positions.AsDeferredJobArray(), ConstraintEdges = constraints.AsDeferredJobArray(), HoleSeeds = holes.AsDeferredJobArray() } } var dependencies = new JobHandle(); dependencies = new GenerateInputJob(positions, constraints, holes).Schedule(dependencies); dependencies = triangulator.Schedule(dependencies); dependencies.Complete(); ``` -------------------------------- ### Utilities.GenerateHalfedges from mesh triangles Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/utilities.md Generates halfedges based on the given triangles. The provided allocator is used for temporary data allocation. Useful when you have mesh data but need to use halfedges, e.g., for iterating through the mesh. ```csharp Mesh mesh = ... var triangles = mesh.triangles; var halfedges = new int[triangles.Length]; Utilities.GenerateHalfedges(halfdeges, triangles, Allocator.Persistent); ``` -------------------------------- ### PlantHoleSeeds with mapping from initial to final triangles Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/advanced/unsafe-triangulator.md Generates a mapping from initial triangles (t1) to triangles after planting seeds (t2). The condition t1[3*i + k] == t2[mapping[3*i + k]] holds for existing triangles; mapping[i] == -1 indicates triangle i no longer exists in t2. ```csharp var t = new UnsafeTriangulator(); using var triangles1 = new NativeList(Allocator.Persistent); t.Triangulate(input, output: new(){ Triangles = triangles1, ... }, args.Default(), Allocator.Persistent); using var mapping = new NativeList(Allocator.Persistent); using var triangles2 = new NativeList(Allocator.Persistent); triangles2.CopyFrom(triangles1); t.PlantHoleSeeds(new(){ Triangles = triangles2, ... }, Allocator.Persistent, mapping: mapping); // The result: // - `triangles1`: the initial triangles buffer before planting seeds. // - `triangles2`: the triangles after planting seeds. // - `mapping`: `triangles1` → `triangles2`. ``` -------------------------------- ### Args.Default() Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/advanced/unsafe-triangulator.md Creates a new LowLevel.Unsafe.Args instance with default values, allowing you to override specific parameters. Use this method to initialize the readonly struct with custom settings. ```APIDOC ## Args.Default() ### Description Creates a new `LowLevel.Unsafe.Args` instance with default values, allowing you to override specific parameters. Use this method to initialize the readonly struct with custom settings. ### Method `Args.Default()` ### Parameters - `refineMesh` (bool) - Optional - Set to `true` to enable mesh refinement. ### Request Example ```csharp var args = Args.Default(refineMesh: true); ``` ``` -------------------------------- ### Schedule triangulation with Unity.Jobs Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/advanced/input-jobs.md Use the Schedule method to add triangulation to a job pipeline. The method takes a JobHandle and returns a new JobHandle that can be passed as dependencies. ```csharp dependencies = triangulator.Schedule(dependencies); ``` -------------------------------- ### Iterate over unique edges using NextHalfedge Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/utilities.md Iterates over all halfedges in a mesh, visiting each edge only once by checking `he > halfedges[he]`, then draws the corresponding line with Gizmos. Useful for edge visualization or processing in triangular meshes. ```csharp var triangles = ... var halfedges = ... var positions = ... for (int he = 0; he < halfedges.Length; he++) { if (he > halfedges[he]) { var e0 = triangles[he]; var e1 = triangles[NextHalfedge(he)]; var p0 = math.float3((float2)positions[e0], 0); var p1 = math.float3((float2)positions[e1], 0); Gizmos.DrawLine(p0, p1); } } ``` -------------------------------- ### Implicit conversion from TriangulationSettings to Args Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/advanced/unsafe-triangulator.md Allows implicit conversion from `TriangulationSettings` to `LowLevel.Unsafe.Args`. This enables you to store settings as a serialized field and cast to args when needed. ```APIDOC ## Implicit conversion from TriangulationSettings to Args ### Description Allows implicit conversion from `TriangulationSettings` to `LowLevel.Unsafe.Args`. This enables you to store settings as a serialized field and cast to args when needed. ### Method Implicit conversion operator ### Request Example ```csharp var settings = new TriangulationSettings(); Args args = settings; ``` ``` -------------------------------- ### Automatic hole detection and boundary restoration with AutoHolesAndBoundary Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/examples/holes-and-boundaries.md Automatically creates holes and restores boundaries based on provided constraints. Uses the even-odd rule, so islands can be nested at any depth. ```csharp using var positions = new NativeArray(..., Allocator.Persistent); using var constraintEdges = new NativeArray(..., Allocator.Persistent); using var triangulator = new Triangulator(Allocator.Persistent) { Input = { Positions = positions, ConstraintEdges = constraintEdges, }, Settings = { AutoHolesAndBoundary = true, }, }; triangulator.Run(); var triangles = triangulator.Output.Triangles; ``` -------------------------------- ### Utilities.BoundingBox Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/utilities.md Returns the axis-aligned bounding box for a provided collection of points. Supports all position types (float2, int2, double2, fp2). ```APIDOC ## Utilities.BoundingBox ### Description Returns the axis-aligned bounding box for a provided collection of points. Supports all position types (`float2`/`int2`/`double2`/`fp2`). ### Method `Utilities.BoundingBox` ### Parameters - `positions` (collection of points) - Required - The collection of points to compute the bounding box for. ### Returns - `(min, max)` - The minimum and maximum corners of the axis-aligned bounding box. ### Request Example ```csharp var positions = new float2[]{ ... }; var (min, max) = Utilities.BoundingBox(positions); ``` ``` -------------------------------- ### Utilities.CenterOfMass for float2 positions Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/utilities.md Returns the center of mass (COM) for a collection of points, assuming equal weights for all positions. Supports all position types (float2/int2/double2/fp2). ```csharp var positions = new float2[]{ ... }; var com = Utilities.CenterOfMass(positions); ``` -------------------------------- ### Implicit conversion from TriangulationSettings to Args Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/advanced/unsafe-triangulator.md LowLevel.Unsafe.Args can be implicitly converted from TriangulationSettings, allowing you to store settings as a serialized field in a MonoBehaviour and cast to Args when needed. ```csharp var settings = new TriangulationSettings(); Args args = settings; ``` -------------------------------- ### Use AsNativeArray with ManagedInput and free handle Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/advanced/input-managed.md Use the AsNativeArray extension to convert a managed C# array into a native array for triangulation input. The handle must be freed manually via Handle.Free() to prevent premature garbage collection. AsNativeArray is allocation-free. ```csharp using var triangulator = new Triangulator(Allocator.Persistent) { Input = new ManagedInput { Positions = new float2[] { new(0, 0), new(1, 0), new(1, 1), new(0, 1) }.AsNativeArray(out var handle) }, }; ... handle.Free(); ``` -------------------------------- ### Args.With() Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/advanced/unsafe-triangulator.md Returns a new `LowLevel.Unsafe.Args` instance with the specified parameters replaced. This method allows you to modify the readonly struct by creating a copy with updated values. ```APIDOC ## Args.With() ### Description Returns a new `LowLevel.Unsafe.Args` instance with the specified parameters replaced. This method allows you to modify the readonly struct by creating a copy with updated values. ### Method `Args.With()` ### Parameters - `refineMesh` (bool) - Required - Set to `true` to enable mesh refinement. ### Request Example ```csharp var args = Args.Default(); args = args.With(refineMesh: true); ``` ``` -------------------------------- ### Set ConstraintEdges input for constrained triangulation Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/examples/constrained-triangulation.md Provides a continuous index array of constraint edges to ensure specific edges are included in the final triangulation. The input array format is [a0, a1, b0, b1, ...] corresponding to edges (a0,a1), (b0,b1), etc. After running, the output triangles fully cover all specified edges. ```csharp using var constraintEdges = new NativeArray(..., Allocator.Persistent); using var positions = new NativeArray(..., Allocator.Persistent); using var triangulator = new Triangulator(Allocator.Persistent) { Input = { Positions = positions, ConstraintEdges = constraintEdges, }, }; triangulator.Run(); var triangles = triangulator.Output.Triangles; ``` -------------------------------- ### Load low-level unsafe namespace Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/advanced/unsafe-triangulator.md Required before using UnsafeTriangulator, similar to Unity.Collections. ```csharp using andywiecko.BurstTriangulator.LowLevel.Unsafe; ``` -------------------------------- ### Triangulate extension with UnsafeTriangulator Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/advanced/unsafe-triangulator.md Simplest extension, equivalent to the Run method for managed Triangulator. Useful for single-job triangulation with Allocator.Temp or combined with other extensions. Uses Args.Default with refineMesh and restoreBoundary set to true. ```csharp using var positions = new NativeArray(..., Allocator.Persistent); using var constraints = new NativeArray(..., Allocator.Persistent); using var holesSeeds = new NativeArray(..., Allocator.Persistent); using var triangles = new NativeList(64, Allocator.Persistent); new UnsafeTriangulator().Triangulate( input: new() { Positions = positions, ConstraintEdges = constraints, HoleSeeds = holesSeeds }, output: new() { Triangles = triangles }, args: Args.Default(refineMesh: true, restoreBoundary: true), allocator: Allocator.Persistent ); ``` -------------------------------- ### Using Triangulator with NativeArray Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/advanced/generic-coordinates.md Shows how to manually select the float2 coordinate type for the generic Triangulator class. The Triangulator has the same API as the default Triangulator (which uses double2), but input/output types match T2. ```csharp using var positions = new NativeArray(..., Allocator.Persistent); using var triangulator = new Triangulator(Allocator.Persistent) { Input = { Positions = positions }, }; triangulator.Run(); ``` -------------------------------- ### Ignore constraints for planting seeds with IgnoreConstraintForPlantingSeeds Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/examples/holes-and-boundaries.md Overrides the 'spreading virus' mechanism for specific constraints, preventing hole detection for those edges. Useful when a constraint should remain part of the final triangulation without generating a hole. ```csharp using var positions = new NativeArray(..., Allocator.Persistent); using var constraintEdges = new NativeArray(..., Allocator.Persistent); using var ignoreConstraint = new NativeArray(..., Allocator.Persistent); using var triangulator = new Triangulator(Allocator.Persistent) { Input = { Positions = positions, ConstraintEdges = constraintEdges, IgnoreConstraintForPlantingSeeds = ignoreConstraint, }, Settings = { AutoHolesAndBoundary = true, }, }; triangulator.Run(); var triangles = triangulator.Output.Triangles; ``` -------------------------------- ### Restore boundaries with RestoreBoundary and ConstraintEdges Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/examples/holes-and-boundaries.md Restores boundaries by setting RestoreBoundary to true and providing edge constraints. Requires both the property and constraint edges to work. ```csharp using var constraintEdges = new NativeArray(..., Allocator.Persistent); using var positions = new NativeArray(..., Allocator.Persistent); using var triangulator = new Triangulator(Allocator.Persistent) { Input = { Positions = positions, ConstraintEdges = constraintEdges, }, Settings = { RestoreBoundary = true, } }; triangulator.Run(); var triangles = triangulator.Output.Triangles; ``` -------------------------------- ### Minimal UnsafeTriangulator usage Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/advanced/unsafe-triangulator.md Low-level API for native contexts. User must manage allocation for input and output. Uses Args.Default() and Allocator.Persistent. ```csharp using var positions = new NativeArray(..., Allocator.Persistent); using var triangles = new NativeList(Allocator.Persistent); new UnsafeTriangulator().Triangulate( input: new() { Positions = positions }, output: new() { Triangles = triangles }, args: Args.Default(), allocator: Allocator.Persistent ); ``` -------------------------------- ### Create holes with HoleSeeds and optional RestoreBoundary Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/examples/holes-and-boundaries.md Creates holes by providing hole positions in the same space as Input.Positions. RestoreBoundary is optional and can be set independently. ```csharp using var constraintEdges = new NativeArray(..., Allocator.Persistent); using var holes = new NativeArray(..., Allocator.Persistent); using var positions = new NativeArray(..., 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; ``` -------------------------------- ### Triangulate Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/advanced/unsafe-triangulator.md The Triangulate extension is the simplest option to use. It produces the same result as the Run method for the managed Triangulator, useful for triangulation with Allocator.Temp in a single job or combined with other extensions. ```APIDOC ## [METHOD] Triangulate ### Description Triangulates the input positions, constraints, and hole seeds, producing triangles in the output. This extension is the simplest option and produces the same result as the Run method for the managed Triangulator. ### Method Triangulate ### Parameters #### Input - **input** (InputData) - Required - Contains Positions, ConstraintEdges, and HoleSeeds. #### Output - **output** (OutputData) - Required - Contains Triangles. #### Arguments - **args** (Args) - Required - Configuration for triangulation, e.g., refineMesh and restoreBoundary. #### Allocator - **allocator** (Allocator) - Required - Memory allocator for temporary data. ### Request Example ```csharp using var positions = new NativeArray(..., Allocator.Persistent); using var constraints = new NativeArray(..., Allocator.Persistent); using var holesSeeds = new NativeArray(..., Allocator.Persistent); using var triangles = new NativeList(64, Allocator.Persistent); new UnsafeTriangulator().Triangulate( input: new() { Positions = positions, ConstraintEdges = constraints, HoleSeeds = holesSeeds }, output: new() { Triangles = triangles }, args: Args.Default(refineMesh: true, restoreBoundary: true), allocator: Allocator.Persistent ); ``` ``` -------------------------------- ### Retriangulate (Extension Method) Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/utilities.md Retriangulates a Unity Mesh with configurable settings. Supports non-uniform meshes and provides options for holes, boundary, refinement, and UV mapping. ```APIDOC ## Retriangulate (Extension Method) ### Description Retriangulates a Unity Mesh with configurable settings. Supports non-uniform meshes and provides options for holes, boundary, refinement, and UV mapping. ### Method mesh.Retriangulate(settings, axisInput, uvMap) ### Parameters - **settings** (RetriangulateSettings) - Required - Configuration for retriangulation, including AutoHolesAndBoundary, RefineMesh, and RefinementThresholds. - **axisInput** (Axis) - Required - The axis plane to use for triangulation (e.g., Axis.XZ). - **uvMap** (UVMap) - Required - The UV mapping strategy (e.g., UVMap.Planar). ### Example ```csharp mesh.Retriangulate( settings: new() { AutoHolesAndBoundary = true, RefineMesh = true, RefinementThresholds = { Angle = 0, Area = 1e-2f } }, axisInput: Axis.XZ, uvMap: UVMap.Planar, ); ``` ``` -------------------------------- ### InsertSubMesh Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/utilities.md Combines meshes by inserting a sub-mesh into the main mesh. Triangle indices are adjusted accordingly, and this method handles that for you. ```APIDOC ## InsertSubMesh ### Description Combines meshes by inserting a sub-mesh into the main mesh. Triangle indices are adjusted accordingly, and this method handles that for you. ### Method InsertSubMesh ### Parameters - **positions** (NativeList) - Required - The main mesh positions list. - **triangles** (NativeList) - Required - The main mesh triangles list. - **subpositions** (float2[]) - Required - The sub-mesh positions. - **subtriangles** (int[]) - Required - The sub-mesh triangles. ### Response No return value. ### Request Example ```csharp using var positions = new NativeList(..., Allocator); using var triangles = new NativeList(..., Allocator); var subpositions = new float2[] { math.float2(0, 0), math.float2(1, 0), math.float2(1, 1) }; var subtriangles = new[] { 0, 1, 2 }; Utilities.InsertSubMesh(positions, triangles, subpositions, subtriangles); ``` ``` -------------------------------- ### NextHalfedge Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/utilities.md Returns the index of the next halfedge for a given halfedge index. Useful for iterating over edges in a triangular mesh. ```APIDOC ## NextHalfedge ### Description Returns the index of the next halfedge for a given halfedge index. Useful for iterating over edges in a triangular mesh. ### Method NextHalfedge(he) ### Parameters - **he** (int) - Required - The halfedge index. ### Returns - **int** - The index of the next halfedge. ### Example ```csharp var triangles = ... var halfedges = ... var positions = ... for (int he = 0; he < halfedges.Length; he++) { if (he > halfedges[he]) { var e0 = triangles[he]; var e1 = triangles[NextHalfedge(he)]; var p0 = math.float3((float2)positions[e0], 0); var p1 = math.float3((float2)positions[e1], 0); Gizmos.DrawLine(p0, p1); } } ``` ``` -------------------------------- ### GeneratePointTriangleCount: count triangles per vertex Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/utilities.md Populates the pointTriangleCount buffer with the number of triangles each vertex index is part of, based on the provided triangles index buffer. The buffer must be large enough to accommodate the highest index in triangles. ```csharp var pointTriangleCount = new int[pointsCount]; Utilities.GeneratePointTriangleCount(pointTriangleCount, triangles); ``` -------------------------------- ### Enable RefineMesh for constrained triangulation Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/examples/constrained-triangulation.md Enables mesh refinement for constrained triangulation, similar to non-constrained refinement. Warning: without restoring boundaries, refinement can produce poor quality results, especially with very acute angles. ```csharp triangulator.Settings.RefineMesh = true; ``` -------------------------------- ### Access Output.Halfedges after triangulation Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/advanced/output-halfedges.md Retrieves the halfedges buffer from a successful triangulation. Halfedges describe neighboring triangles; each entry is the id of the opposite halfedge, or -1 if none exists. All triangles are clockwise. ```csharp using var triangulator = new Triangulator(Allocator.Persistent){ Input = { ... } }; triangulator.Run(); var halfedges = triangulator.Output.Halfedges; ``` -------------------------------- ### GenerateTriangleColors Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/utilities.md Generates triangle colors using the provided halfedges. Triangles that share a common edge are assigned the same color index. The resulting colors contain values in the range [0, colorsCount). ```APIDOC ## GenerateTriangleColors ### Description Generates triangle colors using the provided halfedges. Triangles that share a common edge are assigned the same color index. The resulting colors contain values in the range [0, colorsCount). ### Method GenerateTriangleColors ### Parameters - **colors** (int[]) - Required - Buffer to store the generated color indices. - **halfedges** (int[]) - Required - The halfedges array. - **colorsCount** (out int) - Required - Outputs the number of distinct colors. - **allocator** (Allocator) - Required - The allocator for temporary memory. ### Response No return value. ### Request Example ```csharp var halfedges = new int[] {...}; var colors = new int[halfedges.Length / 3]; Utilities.GenerateTriangleColors(colors, halfedges, out var colorsCount, Allocator.Persistent); ``` ``` -------------------------------- ### Utilities.CenterOfMass Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/utilities.md Returns the center of mass (COM) for a provided collection of points, assuming equal weights for all positions. Supports all position types (float2, int2, double2, fp2). ```APIDOC ## Utilities.CenterOfMass ### Description Returns the center of mass (COM) for a provided collection of points, assuming equal weights for all positions. Supports all position types (`float2`/`int2`/`double2`/`fp2`). ### Method `Utilities.CenterOfMass` ### Parameters - `positions` (collection of points) - Required - The collection of points to compute the center of mass for. ### Returns - `com` - The center of mass of the points. ### Request Example ```csharp var positions = new float2[]{ ... }; var com = Utilities.CenterOfMass(positions); ``` ``` -------------------------------- ### GenerateTriangleColors: assign colors to triangles via halfedges Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/utilities.md Generates triangle colors using the provided halfedges. Triangles sharing a common edge receive the same color index; colors range from 0 to colorsCount-1. Note that triangles sharing only a single vertex may not receive the same color. ```csharp var halfedges = new int[] {...}; var colors = new int[halfedges.Length / 3]; Utilities.GenerateTriangleColors(colors, halfedges, out var colorsCount, Allocator.Persistent); ``` -------------------------------- ### Access Output.ConstrainedHalfedges Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/advanced/output-halfedges.md Retrieves the constrained halfedges buffer after constrained triangulation. Useful for post-processing. If constraint edges are not provided and mesh refinement is enabled, constrained halfedges are automatically set to true for boundary edges (halfedges[i] == -1). ```csharp var constrainedHalfedges = triangulator.Output.ConstrainedHalfedges; ``` -------------------------------- ### Leak Detected Warning in Console Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/known-issues.md Unity Editor may log a leak detection warning related to internal Unity.Collections/Burst bug. Resolved since v3.6 by removing NativeQueue usage. ```bash Leak Detected : Persistent allocates 257 individual allocations. To find out more please enable 'Jobs/LeakDetection/Full StackTraces' and reproduce the leak again. ``` -------------------------------- ### Output.ConstrainedHalfedges Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/advanced/output-halfedges.md Retrieves the constrained halfedges buffer from the triangulation output. This indicates whether a given halfedge is constrained, which is useful for post-processing. ```APIDOC ## Output.ConstrainedHalfedges ### Description Retrieves the constrained halfedges buffer from the triangulation output. This indicates whether a given halfedge is constrained, which is useful for post-processing. ### Method Property access ### Endpoint `triangulator.Output.ConstrainedHalfedges` ### Response #### Success Response - **ConstrainedHalfedges** (NativeArray) - Buffer indicating whether each halfedge is constrained. ### Request Example ```csharp var constrainedHalfedges = triangulator.Output.ConstrainedHalfedges; ``` ``` -------------------------------- ### Enable input validation and check status Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/advanced/input-validation.md Set ValidateInput to true in TriangulationSettings to validate InputData and settings before triangulation. If validation fails, triangulation is not calculated; catch the error via Output.Status.Value. Note that validation can be expensive, so disable it if input is trusted. ```csharp using var triangulator = new Triangulator(Allocator.Persistent) { Input = { ... }, Settings = { ValidateInput = true }, }; triangulator.Run(); var status = triangulator.Output.Status.Value; ``` -------------------------------- ### ProtectConstraints setting Source: https://github.com/andywiecko/bursttriangulator/blob/main/Documentation~/manual/examples/alpha-shape-filter.md Ensures that triangles with any constrained edge are not removed by the alpha-shape filter. Use this to preserve constrained edges in the triangulation. ```csharp triangulator.Settings.AlphaShapeSettings.ProtectConstraints = true; ```