Esempio n. 1
0
    private TextureChunkData GetBestChunkForChunk(TextureChunkData mainChunk, TextureChunkData[] chunksToPullFrom)
    {
        int bestChunkIndex   = -1;
        int lowestDifference = int.MaxValue;

        for (int i = 0; i < chunksToPullFrom.Length; i++)
        {
            TextureChunkData candidateChunk = chunksToPullFrom[i];
            int difference = 0;
            for (int j = 0; j < mainChunk.colors.Length; j++)
            {
                Color32 color1 = mainChunk.colors[j];
                Color32 color2 = candidateChunk.colors[j];
                int     bw1    = color1.r * 30 + color1.g * 59 + color1.b * 11;
                int     bw2    = color2.r * 30 + color2.g * 59 + color2.b * 11;
                int     bwDiff = bw1 - bw2;

                bwDiff = (bwDiff + (bwDiff >> 31)) ^ (bwDiff >> 31); //Absolute Value

                difference += bwDiff;
            }
            if (difference < lowestDifference)
            {
                lowestDifference = difference;
                bestChunkIndex   = i;
            }
        }
        return(chunksToPullFrom[bestChunkIndex]);
    }
Esempio n. 2
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));
        }
    }
Esempio n. 3
0
    //Connect back with main thread
    private static void ReceivedTextureChunkData(object data)
    {
        TextureChunkData thisData = (TextureChunkData)data;

        AddTexture(TextureGenerator.TextureFromColorMap(thisData.colorMap, thisData.width, thisData.height), thisData.chunkCoord);
    }