BurstTriangulator
v3.8.0
Search Results for

    Show / Hide Table of Contents

    Unity.Jobs support

    Add triangulation to job pipeline

    This package supports scheduling with Unity.Jobs. You can learn about the job system here. To schedule triangulation, use the Schedule method:

    dependencies = triangulator.Schedule(dependencies);
    

    Catching errors in the job

    If the triangulation algorithm fails, checking the status and handling it in the job pipeline can be considered. For example:

    [BurstCompile]
    private struct Job : IJob
    {
      NativeReference<Status>.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);
    
    ...
    

    Generating input in the job

    Input can be generated within a job pipeline. You have to use deferred arrays. Here's an example snippet:

    using var positions = new NativeList<double2>(64, Allocator.Persistent);
    using var constraints = new NativeList<int>(64, Allocator.Persistent);
    using var holes = new NativeList<double2>(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();
    
    In this article
    Back to top Generated by DocFX | Documentation © 2024 by Andrzej Więckowski is licensed under CC BY 4.0