void GenerateMap()
    {
        var startTime = DateTime.Now;

        points = BlueNoiseGenerator.PoissonDiscSampling(rMin, rMax, 30, mapSize);
        List <Vertex> scaffolding = BlueNoiseGenerator.Scaffolding(mapSize);

        points.AddRange(scaffolding);

        var duration = DateTime.Now - startTime;

        Debug.Log("SeedPoints Done in " + duration.TotalSeconds + "s");
        startTime = DateTime.Now;

        List <Triangle> convexPoly = Triangulation.TriangulateConvexPolygon(scaffolding);

        triangles = Triangulation.TriangleSplittingAlgorithm(points, convexPoly);
        //triangles = Triangulation.IncrementalAlgorithm(points);

        duration = DateTime.Now - startTime;
        Debug.Log("Triangulation Done in " + duration.TotalSeconds + "s");
        startTime = DateTime.Now;

        triangles = DelaunayTriangulation.MakeTriangulationDelaunay(triangles);

        duration = DateTime.Now - startTime;
        Debug.Log("Delaunayification Done in " + duration.TotalSeconds + "s");
        startTime = DateTime.Now;

        triangles = DelaunayTriangulation.FillInNeighbours(triangles);

        duration = DateTime.Now - startTime;
        Debug.Log("Neighbours Done in " + duration.TotalSeconds + "s");
        startTime = DateTime.Now;

        // fill heightmap into y coordinates
        points = HeightField.PerlinIsland(points, mapSize, 0.1f, 0.7f, 4f, 3f, 6);

        duration = DateTime.Now - startTime;
        Debug.Log("Heightmap Done in " + duration.TotalSeconds + "s");
        startTime = DateTime.Now;

        triangles = Voronoi.GenerateCentroids(triangles, points);

        duration = DateTime.Now - startTime;
        Debug.Log("Centroids Done in " + duration.TotalSeconds + "s");
        startTime = DateTime.Now;

        cells = CellMeshCreator.SpawnMeshes(points, cell);

        duration = DateTime.Now - startTime;
        Debug.Log("Meshes Done in " + duration.TotalSeconds + "s");

        var camHeight = mapSize * 0.5f / Mathf.Tan(Camera.main.fieldOfView * 0.5f * Mathf.Deg2Rad);

        Camera.main.transform.position = new Vector3(mapSize / 2, camHeight * 1.1f, mapSize / 2);

        //DebugDraw();
    }
Example #2
0
    private void UpdateTexture()
    {
        if (texture == null)
        {
            CreateTexture();
        }

        // Clear
        var pixels = texture.GetPixels32();

        for (var i = 0; i < pixels.Length; i++)
        {
            pixels[i] = Color.black;
        }

        texture.SetPixels32(pixels);

        // Sample
        material.mainTexture = texture;

        INoiseGenerator noiseGenerator;

        switch (generatorType)
        {
        case GeneratorType.WhiteNoise:
            noiseGenerator = new WhiteNoiseGenerator(TextureSize);
            break;

        case GeneratorType.HaltonNoise:
            noiseGenerator = new HaltonNoiseGenerator(TextureSize);
            break;

        case GeneratorType.BlueNoise:
            noiseGenerator = new BlueNoiseGenerator(TextureSize);
            break;

        default:
            throw new ArgumentOutOfRangeException();
        }
        for (var i = 0; i < sampleCount; i++)
        {
            var point = noiseGenerator.Next();
            texture.SetPixel((int)point.x, (int)point.y, Color.white);
        }

        texture.Apply();
    }