예제 #1
0
 private void FloodFillSimultaneous(ref List <List <VoronoiTile> > colors, List <Material> replacements, ref List <VoronoiTile> allTiles)
 {
     while (!AreAllProcessed(ref allTiles))
     {
         for (int colorIndex = 0; colorIndex < colors.Count; ++colorIndex) // for each node in colors, fill neighbors
         {
             List <VoronoiTile> newNodes = new List <VoronoiTile>();
             for (int tileIndex = 0; tileIndex < colors[colorIndex].Count; tileIndex++) // go over each node in the colors (first step only one) and fill neighbors
             {
                 VoronoiTile tile = colors[colorIndex][tileIndex];
                 FillNeighbors(tile, replacements[0], colorIndex); // changed here
                 foreach (var neighbor in tile.neighbors)
                 {
                     //neighbor.processed = true;
                     foreach (var nbr in neighbor.neighbors)
                     {
                         if (!nbr.processed)
                         {
                             newNodes.Add(nbr);
                         }
                     }
                 }
             }
             colors[colorIndex].Clear();
             colors[colorIndex] = newNodes;
         }
     }
 }
예제 #2
0
    private void GenerateBestTileCandidates(ref List <VoronoiTile> samples, int depth, ref List <VoronoiTile> allTiles)
    {
        if (depth == 1)
        {
            return;
        }
        List <VoronoiTile> candidates = new List <VoronoiTile>();

        for (int i = 0; i < 10; ++i)
        {
            VoronoiTile tile = allTiles[Random.Range(0, allTiles.Count)];
            candidates.Add(tile);
        }
        VoronoiTile bestCandidate   = candidates.First();
        bool        isFirst         = true;
        float       largestDistance = 0;

        foreach (var candidate in candidates)
        {
            VoronoiTile closest  = FindClosestTile(candidate, ref samples);
            float       distance = Vector3.Distance(closest.centerPoint, candidate.centerPoint);
            if (isFirst || distance > largestDistance)
            {
                largestDistance = distance;
                bestCandidate   = candidate;
                isFirst         = false;
            }
        }
        samples.Add(bestCandidate);
        GenerateBestTileCandidates(ref samples, depth - 1, ref allTiles);
    }
예제 #3
0
    private List <VoronoiTile> GeneratePlateStartNodes(int count, ref List <VoronoiTile> allTiles)
    {
        VoronoiTile        firstTile = allTiles[Random.Range(0, allTiles.Count)];
        List <VoronoiTile> nodes     = new List <VoronoiTile>();

        nodes.Add(firstTile);
        GenerateBestTileCandidates(ref nodes, count, ref allTiles);
        return(nodes);
    }
예제 #4
0
 private void FillNeighbors(VoronoiTile node, Material replacement, int plateNumber)
 {
     if (node.processed == false)
     {
         node.GetComponent <MeshRenderer>().material = replacement;
         node.plate     = plateNumber;
         node.processed = true;
     }
     foreach (var neighbor in node.neighbors)
     {
         if (neighbor.processed == false)
         {
             neighbor.GetComponent <MeshRenderer>().material = replacement;
             neighbor.plate     = plateNumber;
             neighbor.processed = true;
         }
     }
 }
예제 #5
0
    private VoronoiTile FindClosestTile(VoronoiTile tile, ref List <VoronoiTile> samples)
    {
        VoronoiTile closest          = tile;
        bool        isFirst          = true;
        float       smallestDistance = 0;

        foreach (var sample in samples)
        {
            float distance = Vector3.Distance(sample.centerPoint, tile.centerPoint);
            if (isFirst || distance < smallestDistance)
            {
                smallestDistance = distance;
                closest          = sample;
                isFirst          = false;
            }
        }
        return(closest);
    }