Exemple #1
0
    public void DrawMapInEditor()
    {
        //Used to store prefab objects in edit mode and delete them when changes are made (is a bit buggy)
        if (_biomeContainer != null)
        {
            DestroyImmediate(_biomeContainer.gameObject);
        }
        _biomeContainer = new GameObject("DELETE ME IF MANY OF ME").transform;

        //Apply material to mesh
        _textureData.ApplyToMaterial(_terrainMaterial);
        _textureData.UpdateMeshHeights(_terrainMaterial, _heightMapSettings.MinHeight, _heightMapSettings.MaxHeight);

        //Generate the heightmap for the chunk at origin
        HeightMap heightMap = HeightMapGenerator.GenerateHeightMap(_meshSettings.NumVertsPerLine, _meshSettings.NumVertsPerLine, _heightMapSettings, _chunkCoord);

        Vector2 sampleCenter = _chunkCoord * _meshSettings.MeshWorldSize / _meshSettings.MeshScale;

        float[,] noise1 = Noise.GenerateNoiseMap(_meshSettings.NumVertsPerLine * _noiseViewSize, _meshSettings.NumVertsPerLine * _noiseViewSize, 1, _noiseSettingsData_1.NoiseSettingsDataMerge, _chunkCoord);
        noise1          = Noise.Clamp(noise1, _noiseSettingsData_1);
        float[,] noise2 = Noise.GenerateNoiseMap(_meshSettings.NumVertsPerLine * _noiseViewSize, _meshSettings.NumVertsPerLine * _noiseViewSize, 1, _noiseSettingsData_2.NoiseSettingsDataMerge, _chunkCoord);
        noise2          = Noise.Clamp(noise2, _noiseSettingsData_2);

        float[,] noise = _noiseMergeType == NoiseMergeType.ONLY_FIRST ? noise1 : noise2;



        if (_drawMode == DrawMode.NOISE_MAP)
        {
            DrawTexture(TextureGenerator.TextureFromNoise(noise));
        }
        else if (_drawMode == DrawMode.MESH)
        {
            DrawMesh(MeshGenerator.GenerateTerrainMesh(heightMap.heightMap, _meshSettings, _editorPreviewLevelOfDetail));
        }
        else if (_drawMode == DrawMode.FALL_OF_MAP)
        {
            float[,] fallOf = (new HeightMap(FallofGenerator.GenerateFallofMap(_meshSettings.NumVertsPerLine), 1, 1).heightMap);
            DrawTexture(TextureGenerator.TextureFromNoise(fallOf));
        }
        else if (_drawMode == DrawMode.BIOME)
        {
            MeshData meshData = MeshGenerator.GenerateTerrainMesh(heightMap.heightMap, _meshSettings, _editorPreviewLevelOfDetail);
            DrawMesh(meshData);
            PrefabSpawner    prefabSpawner = new PrefabSpawner();
            List <SpawnInfo> spawnInfo     = prefabSpawner.SpawnOnChunk(2, 0, _biome, heightMap, meshData, _meshSettings, new Vector2(sampleCenter.x, -sampleCenter.y), _chunkCoord);
            prefabSpawner.SpawnSpawnInfo(spawnInfo, _biomeContainer, true);
        }
        else if (_drawMode == DrawMode.MAP)
        {
            TextureChunkData data = TextureGenerator.DrawMap(_meshSettings.NumVertsPerLine * _noiseViewSize, _mapSettings, new Vector2(sampleCenter.x, -sampleCenter.y), _chunkCoord);
            DrawTexture(TextureGenerator.TextureFromColorMap(data.colorMap, data.width, data.height));
        }
    }
Exemple #2
0
 //Threaded work
 private static TextureChunkData RequestTextureChunkData(Vector2 chunkCoord, Vector2 sampleCenter)
 {
     return(TextureGenerator.DrawMap(_singleton._meshSettings.NumVertsPerLine, _singleton._mapSettings, sampleCenter, chunkCoord, 1));
 }