src/AnvilPacker/Util/DebugTools.cs
/// <summary> Creates a grayscale PPM file with the heightmaps of all chunks in the region. Assumes heights ranges in [0..255] </summary>
Creates a grayscale PPM file with the heightmaps of all chunks in the region. Assumes heights ranges in [0..255]
Creates a grayscale PPM file with the heightmaps of all chunks in the region . Assumes heights ranges in [ 0 .. 255 ]
public static void DumpHeightmaps(RegionBuffer region, string outPath = "")
        {
            var types = 
                region.ExistingChunks
                    .SelectMany(c => c.Heightmaps)
                    .Select(e => e.Key)
                    .Distinct();
            foreach (var type in types) {
                using var ppm = new DataWriter(File.Create($"{outPath}heightmap_{type}.ppm"));
                ppm.WriteBytes(Encoding.UTF8.GetBytes("P5\n512 512 255\n"));
                for (int z = 0; z < 512; z++) {
                    for (int x = 0; x < 512; x++) {
                        var chunk = region.GetChunk(x >> 4, z >> 4);
                        int height = chunk?.Heightmaps[type]?[x & 15, z & 15] ?? 0;
                        ppm.WriteByte(height);
                    }
                }
            }
        }
public static void DumpHeightmaps ( RegionBuffer region , string outPath = " " ) { var types = region . ExistingChunks . SelectMany ( c => c . Heightmaps ) . Select ( e => e . Key ) . Distinct ( ) ; foreach ( var type in types ) { using var ppm = new DataWriter ( File . Create ( $" { outPath } heightmap_ { type } .ppm " ) ) ; ppm . WriteBytes ( Encoding . UTF8 . GetBytes ( " \n \n " ) ) ; for ( int z = 0 ; z < 512 ; z ++ ) { for ( int x = 0 ; x < 512 ; x ++ ) { var chunk = region . GetChunk ( x >> 4 , z >> 4 ) ; int height = chunk ? . Heightmaps [ type ] ? [ x & 15 , z & 15 ] ?? 0 ; ppm . WriteByte ( height ) ; } } } }
Creates a grayscale PPM file with the heightmaps of all chunks in the region.
Creates a grayscale PPM file with the heightmaps of all chunks in the region .
region
RegionBuffer
outPath
string