Beispiel #1
0
    void Boot()
    {
        t     = GetComponent <Terrain> ();
        tdata = t.terrainData;
        tdata.splatPrototypes    = SplatsFromColors(color_lut);
        tdata.alphamapResolution = tdata.heightmapResolution = twidth;

        float[,] heightmap = new float[twidth, twidth];
        SeedHeightmap(ref heightmap);

        for (int i = 0; i < 5; i++)
        {
            FloatPropagate.Blur(ref heightmap);
        }

        tdata.SetHeights(0, 0, heightmap);
        tdata.SetAlphamaps(0, 0, SplatValuesFromTdata(ref tdata));
    }
Beispiel #2
0
    void SeedHeightmap(ref float[,] heightmap)
    {
        int xdim       = heightmap.GetLength(0);
        int ydim       = heightmap.GetLength(1);
        int seed_count = 3;

        for (int dum = 0; dum < seed_count; dum++)
        {
            int xpos = Random.Range(0, xdim);
            int ypos = Random.Range(0, ydim);

            SpinDown(ref heightmap, xpos, ypos, 1f * dum / seed_count, 5, Random.Range(0f, Mathf.PI * 2f), xdim);
        }

        FloatPropagate.ForcePropagate(ref heightmap, offset: 0.05f);
        for (int i = 0; i < 5; i++)
        {
            FloatPropagate.Blur(ref heightmap);
        }
    }