private void Start()
    {
#if STUPID
        using (new KristerTimer(
                   $"Blue-Noise Generator (Shitty Version, {numObjects} objects)",
                   1))
        {
            spatialPartition =
                new StupidVersion(prefab,
                                  transform,
                                  SqRectilinear,
                                  numObjects);
#elif KDTREE
        using (new KristerTimer($"Blue-Noise Generator (k-d Tree Version, {numObjects} objects)", 1))
        {
            spatialPartition =
                new KdTree(prefab, transform, SqEuclidean, numObjects);
#elif OCTREE
        using (new KristerTimer($"Blue-Noise Generator (Octree Version, {numObjects} objects)", 1))
        {
            spatialPartition = new Octree(prefab, transform, numObjects);
#elif OFFSETOCTREE
        using (new KristerTimer($"Blue-Noise Generator (Offset Octree Version, {numObjects} objects)", 1))
        {
            spatialPartition =
                new OffsetOctree(prefab, transform, numObjects);
#endif

            spatialPartition.Insert(Vector3.zero);

            for (int pointIndex = 1;
                 pointIndex < numObjects;
                 pointIndex++)
            {
                var     bestSqDistance = float.MinValue;
                Vector3 bestCandidate  = default;

                for (int candidateIndex = 0;
                     candidateIndex < (pointIndex * sampleMultiplier) + 1;
                     candidateIndex++)
                {
                    var candidate = GenerateRandomPoint();

                    float sqDistance = float.MinValue;
                    spatialPartition.FindNearestPoint(candidate,
                                                      out GameObject ignored,
                                                      out sqDistance);

                    if (sqDistance > bestSqDistance)
                    {
                        bestCandidate  = candidate;
                        bestSqDistance = sqDistance;
                    }
                }

                spatialPartition.Insert(bestCandidate);
            }
        }
    }
Exemplo n.º 2
0
    private void Update()
    {
        if (_spatialPartition == null)
        {
            Start();
        }

        _spatialPartition.FindNearestPoint(transform.position,
                                           out GameObject nearestObject,
                                           out float nearestSqDist);

        UpdateNearest(nearestObject);
    }