Example #1
0
    /// <summary>
    /// Start generating the mesh.
    /// </summary>
    public void GenerateNewMesh(Vector2[] terrainNoiseOffset, Vector2 biomeNoiseOffset)
    {
        // Disable renderer so the old mesh can't be seen in the new place.
        meshRenderer.enabled = false;

        // Check the terrain tile's 9(3x3 grid) closest voronoi tiles if some tiles are missing create them. Otherwise do nothing.
        VoronoiTiling.GenerateMissingCentroids(transform.position);

        // Get the closest centroids to the terrain tile to have less centroids for the tiles vertices to go through.
        // "amount" is the centroid amount that every vertex in a tile goes through to find the closest one(to get the biome it belongs to).
        // Too small => Artifacts, Too large => Lag spike
        closestCentroids = VoronoiTiling.GetClosestCentroids(transform.position, 5);

        // Stop possible previous coroutines from affecting the latest coroutine
        StopAllCoroutines();

        StartCoroutine(GenerateDraft(terrainNoiseOffset, biomeNoiseOffset));
    }