Пример #1
0
    public void DrawMapInEditor()
    {
        MapData mapData = GenerateMap(Vector2.zero);

        MapDisplay display = FindObjectOfType <MapDisplay>();

        planeObj = GameObject.Find("Plane");
        meshObj  = GameObject.Find("Mesh");
        if (drawMode == DrawMode.NoiseMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(mapData.heightMap));
            planeObj.transform.position = new Vector3(0, 1, 0);
            meshObj.transform.position  = new Vector3(0, -200, 0);
        }
        else if (drawMode == DrawMode.ColourMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromColourMap(mapData.colourMap, mapChunkSize, mapChunkSize));
            planeObj.transform.position = new Vector3(0, 1, 0);
            meshObj.transform.position  = new Vector3(0, -200, 0);
        }
        else if (drawMode == DrawMode.Mesh)
        {
            display.DrawMesh(MeshGenerator.GenerateTerrainMesh(mapData.heightMap, meshHeightMultiplier, meshHeightCurve, levelOfDetail), TextureGenerator.TextureFromColourMap(mapData.colourMap, mapChunkSize, mapChunkSize));
            planeObj.transform.position = new Vector3(0, -200, 0);
            meshObj.transform.position  = new Vector3(0, 1, 0);
        }
        else if (drawMode == DrawMode.FallOfMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(FallOffGenerator.GenerateFallOffMap(mapChunkSize)));
        }
    }
    private MapData GenerateMapData(Vector2 center)
    {
        float[,] noiseMap = Noise.GenerateNoiseMap(mapChunkSize + 2, mapChunkSize + 2, noiseData.seed, noiseData.noiseScale, noiseData.octaves, noiseData.persistance, noiseData.lacunarity, center + noiseData.offset, noiseData.normalizeMode);

        if (terrainData.useFallOff)
        {
            if (fallOffMap == null)
            {
                fallOffMap = FallOffGenerator.GenerateFallOffMap(mapChunkSize + 2);
            }

            for (int y = 0; y < mapChunkSize + 2; y++)
            {
                for (int x = 0; x < mapChunkSize + 2; x++)
                {
                    if (terrainData.useFallOff)
                    {
                        noiseMap[x, y] = Mathf.Clamp01(noiseMap[x, y] - fallOffMap[x, y]);
                    }
                }
            }
        }

        return(new MapData(noiseMap));
    }
Пример #3
0
    public void DrawMapInEditor()
    {
        MapData mapData = GenerateMapData(Vector2.zero);

        //Referencing the MapDisplay method
        MapDisplay display = FindObjectOfType <MapDisplay>();

        //Saying which drawMode we are in and whether to draw the colours or not
        if (drawMode == DrawMode.NoiseMap)
        {
            //Displaying the noise map
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(mapData.heightMap));
        }
        else if (drawMode == DrawMode.ColourMap)
        {
            //Displaying the colour map
            display.DrawTexture(TextureGenerator.TextureFromColourMap(mapData.colourMap, mapChunkSize, mapChunkSize));
        }
        else if (drawMode == DrawMode.Mesh)
        {
            //Displaying the mesh map
            display.DrawMesh(MeshGenerator.GenerateTerrainMesh(mapData.heightMap, meshHeightMultiplier, meshHeightCurve, editorPreviewLOD), TextureGenerator.TextureFromColourMap(mapData.colourMap, mapChunkSize, mapChunkSize));
        }
        else if (drawMode == DrawMode.FallOffMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(FallOffGenerator.GenerateFalloffMap(mapChunkSize)));
        }
    }
    public void DrawMapInEditor()
    {
        textureData.ApplyToMaterial(terrainMaterial);
        textureData.UpdateMeshHeights(terrainMaterial, heightMapSettings.MinHeight, heightMapSettings.MaxHeight);

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

        switch (drawMode)
        {
        case DrawMode.NoiseMap:
            DrawTexture(TextureGenerator.TextureFromHeightMap(heightMap));
            break;

        case DrawMode.Mesh:
            DrawMesh(
                MeshGenerator.GenerateTerrainMesh(heightMap.values, meshSettings, editorPreviewLOD));
            break;

        case DrawMode.FalloffMap:
            DrawTexture(TextureGenerator.TextureFromHeightMap(new HeightMap(FallOffGenerator.GenerateFalloffMap(meshSettings.NumVerticesPerLine), 0, 1)));
            break;

        case DrawMode.CanyonMap:
            DrawTexture(TextureGenerator.TextureFromHeightMap(new HeightMap(CanyonMapGenerator.GenerateCanyonMap(meshSettings.NumVerticesPerLine), 0, 1)));
            break;

        default:
            throw new ArgumentOutOfRangeException();
        }
    }
Пример #5
0
    void Start()
    {
        GameObject meshObject = GameObject.FindGameObjectWithTag("meshObject");

        meshObject.AddComponent <MeshCollider>();
        mapdata    = GenerateMapData();
        falloffMap = FallOffGenerator.GenerateFallOffMap(mapWidth, mapHeight);
    }
Пример #6
0
 private void OnValidate()
 {
     if (lacunarity < 1)
     {
         lacunarity = 1;
     }
     fallOffMap = FallOffGenerator.GenerateFallOffMap(mapChunkSize);
 }
Пример #7
0
    // Use this for initialization
    void Awake()
    {
        fallOff = FallOffGenerator.Generate(grid.gridSizeX);
        seed    = Random.Range(100, 999);

        width  = grid.Width;
        height = grid.Height;

        GenerateIsland();
    }
 void OnValidate()
 {
     if (lacunarity < 1)
     {
         lacunarity = 1;
     }
     if (octaves < 0)
     {
         octaves = 0;
     }
     fallOffMap = FallOffGenerator.GenerateFalloffMap(mapChunkSize);
 }
Пример #9
0
    public static HeightMap GenerateHeightMap(int width, int height, HeightMapSettings settings, Vector2 sampleCenter)
    {
        float[,] values = Noise.GenerateNoiseMap(width, height, settings.NoiseSettings, sampleCenter);

        float[,] fallOff = new float[0, 0];
        float[,] canyon  = new float[0, 0];

        if (settings.UseFalloffMap)
        {
            fallOff = FallOffGenerator.GenerateFalloffMap(width);
        }

        if (settings.UseCanyonMap)
        {
            canyon = CanyonMapGenerator.GenerateCanyonMap(width);
        }

        AnimationCurve heighCurveThreadSafe = new AnimationCurve(settings.HeightCurve.keys);

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

        for (int i = 0; i < width; i++)
        {
            for (int j = 0; j < height; j++)
            {
                if (settings.UseFalloffMap)
                {
                    values[i, j] -= fallOff[i, j];
                }

                if (settings.UseCanyonMap)
                {
                    values[i, j] += canyon[i, j];
                }

                values[i, j] *= heighCurveThreadSafe.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));
    }
Пример #10
0
    void OnValidate()
    {
        //Clamping some important values to not allow them to be below a certain number
        if (lacunarity < 1)
        {
            lacunarity = 1;
        }

        if (octaves < 0)
        {
            octaves = 0;
        }

        falloffMap = FallOffGenerator.GenerateFalloffMap(mapChunkSize);
    }
Пример #11
0
 void OnValidate()
 {
     if (mapWidth < 1)
     {
         mapWidth = 1;
     }
     if (mapHeight < 1)
     {
         mapHeight = 1;
     }
     if (octaves < 0)
     {
         octaves = 0;
     }
     UpdateMeshHeight(terrainMaterial, minHeight, maxHeight);
     falloffMap = FallOffGenerator.GenerateFallOffMap(mapWidth, mapHeight);
 }
    public void DrawMapInEditor()
    {
        MapData mapData = GenerateMapData(Vector2.zero);

        MapDisplay display = FindObjectOfType <MapDisplay>();

        if (drawMode == DrawMode.NoiseMap)
        {
            display.DrawTexture(TextureGenerator.textureFromHeightMap(mapData.heightMap));
        }
        else if (drawMode == DrawMode.Mesh)
        {
            display.DrawMesh(MeshGenerator.GenerateTerrainMesh(mapData.heightMap, terrainData.meshHeightMultiplier, terrainData.meshHeightCurve, editorPreviewLevelOfDetail, terrainData.useFlatShading));
        }
        else if (drawMode == DrawMode.FallOffMap)
        {
            display.DrawTexture(TextureGenerator.textureFromHeightMap(FallOffGenerator.GenerateFallOffMap(mapChunkSize)));
        }
    }
    /// <summary>
    /// Determines the size of the island based on its IslandSize value
    /// </summary>
    public void DetermineSize()
    {
        switch (islandTile.Size)
        {
        case IslandTile.IslandSize.Long:
            islandWidth *= 2;
            break;

        case IslandTile.IslandSize.Tall:
            islandHeight *= 2;
            break;

        case IslandTile.IslandSize.Large:
            islandWidth  *= 2;
            islandHeight *= 2;
            break;
        }
        falloffMap = FallOffGenerator.GenerateFalloffMap(islandWidth, islandHeight);
    }
    public void DrawMapInEditor()
    {
        textureData.ApplyToMaterial(terrainMaterial);
        textureData.UpdateMeshHeights(terrainMaterial, heightMapSettings.minHeight, heightMapSettings.maxHeight);
        HeightMap mapData = HeightMapGenerator.GenerateHeightMap(meshSettings.numVerticesPerLine, meshSettings.numVerticesPerLine, heightMapSettings, Vector2.zero);

        if (drawMode == DrawMode.NoiseMap)
        {
            DrawTexture(TextureGenerator.TextureFromHeightMap(mapData));
        }
        else if (drawMode == DrawMode.Mesh)
        {
            DrawMesh(MeshGenerator.GenerateTerrainMesh(mapData.values, meshSettings, editorPreviewLOD));
        }
        else if (drawMode == DrawMode.FalloffMap)
        {
            DrawTexture(TextureGenerator.TextureFromHeightMap(new HeightMap(FallOffGenerator.GenerateFalloffMap(meshSettings.numVerticesPerLine), 0, 1)));
        }
    }
    public void DrawMapInEditor()
    {
        textureData.ApplyToMaterial(terrainMaterial);
        textureData.UpdateMeshHeights(terrainMaterial, heightMapSettings.minHeight, heightMapSettings.maxHeight);
        HeightMap heightMap = HeightMapGenerator.GenerateHeightMap(meshSettings.numberOfVerticesPerLine, meshSettings.numberOfVerticesPerLine, heightMapSettings, Vector2.zero);

        switch (drawMode)
        {
        case DrawMode.NoiseMap:
            DrawTextureMap(TextureGenerator.TextureFromHeightMap(heightMap));
            break;

        case DrawMode.Mesh:
            DrawMesh(MeshGenerator.GenerateTerrainMesh(heightMap.values, meshSettings, editorPreviewLOD));
            break;

        case DrawMode.FallOffMap:
            DrawTextureMap(TextureGenerator.TextureFromHeightMap(new HeightMap(FallOffGenerator.GenerateFallOffMap(meshSettings.numberOfVerticesPerLine), 0, 1)));
            break;
        }
    }
    void OnValidate()
    {
        if (lacunarity < 1)
        {
            lacunarity = 1;
        }
        if (octaves < 0)
        {
            octaves = 0;
        }

        if (density < 0)
        {
            density = 0;
        }

        if (useFalloff)
        {
            falloffMap = FallOffGenerator.GenerateFalloffMap(textQual);
        }
    }
Пример #17
0
    public void DrawMapInEditor()
    {
        MapData    mapData = GenerateMapData(Vector2.zero);
        MapDisplay display = FindObjectOfType <MapDisplay>();

        if (drawMode == DrawMode.NoiseMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(mapData.heightMap));
        }
        else if (drawMode == DrawMode.ColourMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromColourMap(mapData.colourMap, mapChunkSize, mapChunkSize));
        }
        else if (drawMode == DrawMode.Mesh)
        {
            display.DrawMesh(MeshGenerator.GenerateTerrainMesh(mapData.heightMap, meshHeightMultiplier, meshHeightCurve, editorPreviewLOD), TextureGenerator.TextureFromColourMap(mapData.colourMap, mapChunkSize, mapChunkSize));
        }
        else if (drawMode == DrawMode.FallOffMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(FallOffGenerator.GenerateFallOffMap(mapChunkSize)));
        }
    }
Пример #18
0
    public static HeightMap GenerateHeightMap(int width, int height, HeightMapSettings settings, Vector2 sampleCentre)
    {
        float[,] values = Noise.GenerateNoiseMap(width, height, settings.noiseSettings, sampleCentre);

        AnimationCurve heightCurve_threadsafe = new AnimationCurve(settings.heightCurve.keys); //gets all keys defined in the animation curve

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

        if (settings.generateIsland)
        {
            if (fallOffMap == null)
            {
                fallOffMap = FallOffGenerator.GenerateFalloffMap(width);
            }
        }

        for (int i = 0; i < width; i++)
        {
            for (int j = 0; j < height; j++)
            {
                //adjusts values by evaluating to the height curve and multiplying by the height multiplier
                values[i, j] *= heightCurve_threadsafe.Evaluate(values[i, j] - (settings.generateIsland ? fallOffMap[i, j] : 0)) * settings.heightMultipier;

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

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

        return(new HeightMap(values, minValue, maxValue));
    }
    //void Awake(){
    //	instance = this;
    //}

    //public ObjectPlacer objTest;
    //private int awayLOD;
    void Start()
    {
        //seed = (int)System.DateTime.Now.Ticks;
        //awayLOD = LOD;
        falloffMap = FallOffGenerator.GenerateFalloffMap(textQual);
        if (player != null)
        {
            distThread = new TerrainUpdater();
        }
        //QualitySettings.shadowDistance = radius;
        for (int i = 0; i < lodLevel.Length; i++)
        {
            lodLevel [i].distance *= radius;
        }
        if (psh == null)
        {
            psh = gameObject.GetComponent <SpawningManager> ();
        }

        GenerateMap(true);
//		if (placeOnStart)
//			createTrees ();
    }
Пример #20
0
    public void DrawMapInEditor()
    {
        MapData mapData = GenerateMapData();

        MapDisplay display = FindObjectOfType <MapDisplay>();

        if (drawMode == DrawMode.NoiseMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(mapData.heightMap));
        }
        else if (drawMode == DrawMode.ColourMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromColourMap(mapData.colorMap, mapWidth, mapHeight));
        }
        else if (drawMode == DrawMode.Mesh)
        {
            display.DrawMesh(MeshGenerator.GenerateTerrainMesh(mapData.heightMap, meshHeightMultiplier, meshHeightCurve), TextureGenerator.TextureFromColourMap(mapData.colorMap, mapWidth, mapHeight));
        }
        else if (drawMode == DrawMode.FalloffMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(FallOffGenerator.GenerateFallOffMap(mapWidth, mapHeight)));
        }
    }
Пример #21
0
    MapData generateMapData(Vector2 centre)
    {
        float[,] noiseMap = Noise.GenerateNoiseMap(mapChunkSize + 2, mapChunkSize + 2, noiseData.seed, noiseData.noiseScale, noiseData.octave, noiseData.persistent, noiseData.lacunarity, centre + noiseData.offSet, noiseData.normalizeMode);
        if (terrainData.useFallOff)
        {
            if (fallOffMap == null)
            {
                fallOffMap = FallOffGenerator.fallOffMap(mapChunkSize + 2);
            }
            for (int y = 0; y < mapChunkSize + 2; y++)
            {
                for (int x = 0; x < mapChunkSize + 2; x++)
                {
                    if (terrainData.useFallOff)
                    {
                        noiseMap[x, y] = Mathf.Clamp(noiseMap[x, y] - fallOffMap[x, y], 0, 1);
                    }
                    float currentHeight = noiseMap[x, y];
                }
            }
        }

        return(new MapData(noiseMap));
    }
Пример #22
0
    public void GenerateMap()
    {
        if (!Application.isPlaying)
        {
            return;
        }

        float[,] noiseMap = NoiseGenerator.GenerateNoise(mapChunkSize, mapChunkSize, seed, noiseScale, octaves, persistance, lacunarity, offset);
        Color[]       colorMap   = new Color[mapChunkSize * mapChunkSize];
        TileTerrain[] terrainMap = new TileTerrain[(mapChunkSize - 1) * (mapChunkSize - 1)];


        for (int x = 0; x < mapChunkSize; x++)
        {
            for (int y = 0; y < mapChunkSize; y++)
            {
                if (useFallOff)
                {
                    noiseMap[x, y] = Mathf.Clamp01(noiseMap[x, y] - fallOffMap[x, y]);
                }

                float currentHeight = noiseMap[x, y];
                for (int i = 0; i < TerrainSettingsManager.Instance.regions.Length; i++)
                {
                    if (currentHeight <= TerrainSettingsManager.Instance.regions[i].height && currentHeight <= 1)
                    {
                        colorMap[y * mapChunkSize + x] = TerrainSettingsManager.Instance.regions[i].color;
                        if (x < (mapChunkSize - 1) && y < (mapChunkSize - 1))
                        {
                            terrainMap[y * (mapChunkSize - 1) + x] = TerrainSettingsManager.Instance.regions[i].type;
                        }
                        break;
                    }
                }
            }
        }

        RiverReturn river = RiverGenerator.GenerateRivers(noiseMap);

        int t;

        for (t = 0; t < river.riverPoints.Length; t++)
        {
            int x = (int)river.riverPoints[t].x;
            int y = (int)river.riverPoints[t].y;
            //Instantiate(GameObject.CreatePrimitive(PrimitiveType.Cube), new Vector3(y,5,x), Quaternion.identity);
            colorMap[y * mapChunkSize + x]         = TerrainSettingsManager.Instance.regions[9].color;
            terrainMap[y * (mapChunkSize - 1) + x] = TerrainSettingsManager.Instance.regions[9].type;
        }

        MapDisplay mapDisplay = FindObjectOfType <MapDisplay>();

        if (drawmode == DrawMode.noiseMap)
        {
            mapDisplay.DrawTexture(TextureGenerator.NoiseTextureFromHeightMap(noiseMap));
        }
        else if (drawmode == DrawMode.ColorMap)
        {
            mapDisplay.DrawTexture(TextureGenerator.TextureFromColorMap(colorMap, mapChunkSize, mapChunkSize));
        }
        else if (drawmode == DrawMode.Mesh)
        {
            map.Initialize(noiseMap, meshHeightMultiplier, meshHeightCurve, levelOfDetail, terrainMap);
            map.BuildMesh();
            GameTile[] tiles = map.GenerateGameTiles();
            map.ApplyTexture(TextureGenerator.TextureFromColorMap(colorMap, mapChunkSize, mapChunkSize));

            fogofwar.Initialize(map.Vertices, map.Triangles, map.Uvs, noiseMap.GetLength(0), noiseMap.GetLength(1));
            TerrainFeaturePlacer.Instance.PlaceFeatures();


            player.Instantiate(map.GetNearestTile(tiles[((mapChunkSize - 1) * (mapChunkSize - 1)) / 2], TileTerrain.Land, TileFeatures.Village, 30));
            fogofwar.ClearFog(player.Tile, 3);
        }
        else if (drawmode == DrawMode.FallOffMap)
        {
            mapDisplay.DrawTexture(TextureGenerator.NoiseTextureFromHeightMap(FallOffGenerator.GenerateFallOffMap(mapChunkSize)));
        }
    }
Пример #23
0
 public void Awake()
 {
     fallOffMap = FallOffGenerator.GenerateFallOffMap(mapChunkSize);
 }
 private void Start()
 {
     fallOffMap = FallOffGenerator.GenerateFallOffMap(mapChunkSize);
 }
Пример #25
0
 void Awake()
 {
     falloffMap = FallOffGenerator.GenerateFallOffMap(mapWidth, mapHeight);
 }
Пример #26
0
 private void Awake()
 {
     fallOffMap = FallOffGenerator.GenerateFallOffofMap(mapChunkSize);
 }