public void Generate()
        {
            if (Randomize)
            {
                Offset = Random.Range(0f, 9999f);
            }

            TerrainData terrainData = Terrain.activeTerrain.terrainData;

            terrainData.heightmapResolution = Width + 1;
            terrainData.alphamapResolution  = Width;
            terrainData.SetDetailResolution(Width, 8);

            terrainData.size = new Vector3(Width, Depth, Height);

            float[,] falloff = null;
            if (UseFalloffMap)
            {
                falloff = new FalloffMap
                {
                    FalloffDirection = FalloffDirection,
                    FalloffRange     = FalloffRange,
                    Size             = Width
                }.Generate();
            }

            float[,] noiseMap = GenerateNoise(falloff);
            terrainData.SetHeights(0, 0, noiseMap);
        }
Example #2
0
    private void UpdateFalloffMap()
    {
        falloffMap = MapGenerator.GenerateFalloffMap(mapWidth, currentFalloffMapSettings);

        falloffMapPreviewImage.texture = TextureGenerator.TextureFromFloatArray2D(falloffMap.values, Color.black, Color.white);

        UpdateHeightMap();
    }
Example #3
0
    private void CreateMaps()
    {
        falloffMap = MapGenerator.GenerateFalloffMap(mapWidth, currentFalloffMapSettings);
        heightMap  = MapGenerator.GenerateHeightMap(mapWidth, mapHeight, currentHeightMapSettings, falloffMap, Vector2.zero);

        treeBiomeMap   = MapGenerator.GenerateBiomeMap(clutterMapWidth, clutterMapWidth, currentTreeBiomeMapSettings, Vector2.zero, true);
        rockBiomeMap   = MapGenerator.GenerateBiomeMap(clutterMapWidth, clutterMapWidth, currentRockBiomeMapSettings, Vector2.zero, true);
        treeClutterMap = MapGenerator.GenerateClutterMap(clutterMapWidth, clutterMapWidth, currentTreeMapSettings, Vector2.zero, treeBiomeMap, true);
        rockClutterMap = MapGenerator.GenerateClutterMap(clutterMapWidth, clutterMapWidth, currentRockMapSettings, Vector2.zero, rockBiomeMap, true);

        previewMap = MapGenerator.GeneratePreviewMap(mapWidth, mapHeight, worldMinHeight, worldMaxHeight, previewSettings, heightMap, currentTextureSettings /*, new ClutterMap[] { rockClutterMap, treeClutterMap }*/);

        //treeBiomeMapSeed = currentTreeBiomeMapSettings.noiseSettings.seed;
        //rockBiomeMapSeed = currentRockBiomeMapSettings.noiseSettings.seed;

        //treeMapSeed = currentTreeMapSettings.noiseSettings.seed;
        //rockMapSeed = currentRockMapSettings.noiseSettings.seed;
    }
    public void EditorDrawMap()
    {
        textureData.UpdateMeshHeights(terrainMaterial, heightMapSettings.minHeight, heightMapSettings.maxHeight);

        HeightMap heightMap = HeightMapGenerator.GenerateHeightMap(meshSettings.numVertsPerLine, meshSettings.numVertsPerLine, heightMapSettings, Vector2.zero);

        MapDisplay mapDisplay = FindObjectOfType <MapDisplay>();

        if (drawMode == DrawMode.NoiseMap)
        {
            mapDisplay.TextureDrawer(TextureGenerator.TextureFromHeightMap(heightMap.values));
        }
        else if (drawMode == DrawMode.Mesh)
        {
            mapDisplay.DrawMesh(MeshGenerator.TerrainMeshGenerator(heightMap.values, meshSettings, editorLOD));
        }
        else if (drawMode == DrawMode.FalloffMap)
        {
            mapDisplay.TextureDrawer(TextureGenerator.TextureFromHeightMap(FalloffMap.GenerateFalloffMap(meshSettings.numVertsPerLine)));
        }
    }
Example #5
0
    public static HeightMap GenerateHeightMap(int width, int height, HeightMapSettings settings, FalloffMap falloffMap, Vector2 sampleCenter)
    {
        float[,] values = NoiseGenerator.GeneratePerlinNoiseMap(width, height, settings.noiseSettings, sampleCenter);

        float minValue = float.MaxValue;
        float maxValue = float.MinValue;

        for (int i = 0; i < width; i++)
        {
            for (int j = 0; j < height; j++)
            {
                if (settings.useFalloff)
                {
                    values[i, j] *= settings.heightCurve.Evaluate(values[i, j]) * settings.heightMultiplier * falloffMap.values[i, j];
                }
                else
                {
                    values[i, j] *= settings.heightCurve.Evaluate(values[i, j]) * settings.heightMultiplier;
                }

                if (values[i, j] > maxValue)
                {
                    maxValue = values[i, j];
                }

                if (values[i, j] < minValue)
                {
                    minValue = values[i, j];
                }
            }
        }

        return(new HeightMap(values, minValue, maxValue));
    }