Example #1
0
        public static void InitializeMesh(ViewableRegion region, VoronoiGraph vG, Mesh mesh, Noise noise, int maxWaterLevelDisplacement)
        {
            List <Vector3> vertices  = new List <Vector3>();
            List <int>     triangles = new List <int>();

            float water_elevation = region.getWaterLevelElevation();

            Vector3[] verticesLocal;
            Vector3[] trianglesLocal = new Vector3[] { new Vector3(0, 1, 2), new Vector3(0, 1, 3) };

            SiteSorterSiteNBR sorter = new SiteSorterSiteNBR();
            int count = 0;

            foreach (GraphEdge edge in vG.edges)
            {
                // locate voronoi sites for the edge
                Site site1, site2;
                site1 = vG.sites[sorter.searchSites(vG.sites, edge.site1)];
                site2 = vG.sites[sorter.searchSites(vG.sites, edge.site2)];
                // compute vertex coordinates
                verticesLocal = new Vector3[] {
                    new Vector3((float)edge.x1, water_elevation, (float)edge.y1),
                    new Vector3((float)edge.x2, water_elevation, (float)edge.y2),
                    new Vector3((float)site1.coord.x - region.getViewableSize() / 2, water_elevation, (float)site1.coord.y - region.getViewableSize() / 2),
                    new Vector3((float)site2.coord.x - region.getViewableSize() / 2, water_elevation, (float)site2.coord.y - region.getViewableSize() / 2)
                };
                // add noisy elevation to each vertex
                for (int i = 0; i < verticesLocal.Length; i++)
                {
                    Vector3 v   = verticesLocal[i];
                    float   val = noise.getNoiseValueAt((int)v.x + region.getViewableSize() / 2, (int)v.z + region.getViewableSize() / 2, (int)(region.getViewableSize() * 1.5f));
                    v.y += (-0.5f + val) * maxWaterLevelDisplacement;
                    verticesLocal[i] = v;
                }
                // add triangles to the mesh
                foreach (Vector3 triangle in trianglesLocal)
                {
                    MeshGenerator.addTriangle(triangle, verticesLocal, vertices, triangles);
                    count++;
                }
            }
            // set mesh
            mesh.vertices  = vertices.ToArray();
            mesh.triangles = triangles.ToArray();
            mesh.RecalculateNormals();

            //Debug.Log("Initialized water mesh with " + count + " triangles.");
        }
    public bool regenerateVoronoi(bool drawmesh)
    {
        if (GameControl.gameSession == null || (region = GameControl.gameSession.mapGenerator.getRegion()) == null)
        {
            //Debug.Log("Cannot regenerate Voronoi for Water - gameSession is not ready.");
            return(false);
        }

        // prepare noise
        int   noise_seed = (useRandomSeed) ? UnityEngine.Random.Range(int.MinValue, int.MaxValue) : this.seed;
        Noise noise      = new FastPerlinNoise(noiseResolution, noise_seed, noiseAmplitude, noisePersistance);

        noise.setNoiseValues(NoiseMap.adjustNoise(noise.getNoiseValues(), 5));

        // get region parameters
        this.water_elevation = region.getWaterLevelElevation();
        this.size            = region.getViewableSize();
        int halfSize = this.size / 2;

        // generate random coordinates for polygons
        generateXY(out this.X, out this.Y);

        // use voronoi generator
        voronoi = new Voronoi(minDist);
        voronoi.generateVoronoi(X, Y, 0, size, 0, size);

        VoronoiGraph vG = voronoi.getVoronoiGraph();

        foreach (GraphEdge gE in vG.edges)
        {
            gE.x1 -= halfSize;
            gE.x2 -= halfSize;
            gE.y1 -= halfSize;
            gE.y2 -= halfSize;
        }

        if (drawmesh)
        {
            Meshes.WaterMesh.InitializeMesh(region, voronoi.getVoronoiGraph(), mesh, noise, maxWaterLevelDisplacement);
        }
        return(true);
    }
Example #3
0
    // initialize the region parameters
    public static void InitializeWorldGenerationParams(ViewableRegion region)
    {
        // TODO load from XML

        // world temperature parameters
        worldAmbientTemperature = 60f;
        worldScale           = region.getViewableSize() / 50;
        worldCoreTemperature = 175f;
        tanFalloffTemp       = 0.01f;
        linFalloffTemp       = 0.05f;
        latitudeFactorTemp   = 0.025f;

        // erosion parameters
        erosionWaterAmount          = 1f;
        erosionStrength             = 1f;
        erosionWaterLoss            = 0.98f;
        erosionIterations           = 100;
        earthStability              = 0.25f;
        erosionVelocityElevationCap = 25f;

        // region features
        forestryProbability = 0.1f;
        forestryMaxSpread   = 25f;
    }