Class TerrainRenderer
- Namespace
- Valheim.Testing
- Assembly
- Valheim.Testing.dll
Renders an ITerrain into an RGB image for review. The image covers Area with square pixels of MetresPerPixel; +x points right and +z points up (north up). Each pixel shows the terrain sampled once at its centre. Contours are drawn over the terrain, then polylines in the order added, then points. The same inputs give the same bytes on every platform, provided the terrain itself answers the same heights. A terrain that refuses a coordinate (outside a grid, an uncaptured replay sample, a missing biome layer) fails the render; nothing is painted in its place. A picture of an input is not evidence the game agrees.
public sealed class TerrainRenderer
- Inheritance
-
objectTerrainRenderer
Constructors
TerrainRenderer(TerrainArea, float)
The area's width and depth must each be a whole number of pixels.
public TerrainRenderer(TerrainArea area, float metresPerPixel)
Parameters
areaTerrainAreametresPerPixelfloat
Fields
MaxPixels
Largest width or height in pixels, to refuse accidentally huge renders.
public const int MaxPixels = 8192
Field Value
- int
Properties
Area
public TerrainArea Area { get; }
Property Value
Coloring
public TerrainColoring Coloring { get; set; }
Property Value
Height
public int Height { get; }
Property Value
- int
HighHeight
Height mode: the height drawn white.
public float HighHeight { get; set; }
Property Value
- float
LowHeight
Height mode: the height drawn darkest (deep water, or the lowest land without water).
public float LowHeight { get; set; }
Property Value
- float
MetresPerPixel
public float MetresPerPixel { get; }
Property Value
- float
WaterLevel
Height mode: heights below this are drawn as water; null draws every height as land. The game's sea level is 30.
public float? WaterLevel { get; set; }
Property Value
- float?
Width
public int Width { get; }
Property Value
- int
Methods
BiomeColor(TerrainBiome)
Biome mode colour: one fixed colour per biome; Unknown is magenta.
public static RenderColor BiomeColor(TerrainBiome biome)
Parameters
biomeTerrainBiome
Returns
Contours(float, RenderColor)
Adds contour lines at WaterLevel (the game's sea level, 30 m, when it is null) and every
interval metres above and below it.
A pixel is drawn when a 4-neighbour's height lies below a level its own height reaches, so each line is one pixel
wide on its uphill side and the coastline is always one of the lines. Heights are the pixel-centre samples the
terrain answers, in either colouring mode; between nodes of a grid those are its interpolation, not the game's.
public TerrainRenderer Contours(float interval, RenderColor color)
Parameters
intervalfloatcolorRenderColor
Returns
HeightColor(float)
Height mode colour. Water (below WaterLevel) runs from light blue at the water level to dark blue at LowHeight. Land runs green, brown, white from the water level (or LowHeight) to HighHeight, brown at the midpoint. Heights beyond the range take the end colour.
public RenderColor HeightColor(float height)
Parameters
heightfloat
Returns
PixelX(int)
World x of a pixel column's centre.
public float PixelX(int px)
Parameters
pxint
Returns
- float
PixelZ(int)
World z of a pixel row's centre; row 0 is the top (largest z).
public float PixelZ(int py)
Parameters
pyint
Returns
- float
Point(float, float, RenderColor, int)
Adds a filled disc: every pixel whose offset (dx, dy) from the point's pixel has dxdx + dydy <= radius*radius.
public TerrainRenderer Point(float x, float z, RenderColor color, int radius = 2)
Parameters
xfloatzfloatcolorRenderColorradiusint
Returns
Polyline(IEnumerable<(float x, float z)>, RenderColor)
Adds straight one-pixel segments (Bresenham) between the pixels holding consecutive points.
public TerrainRenderer Polyline(IEnumerable<(float x, float z)> points, RenderColor color)
Parameters
pointsIEnumerable<(float x, float z)>colorRenderColor
Returns
Render(ITerrain)
public TerrainImage Render(ITerrain terrain)
Parameters
terrainITerrain
Returns
ToPixel(float, float)
The pixel holding a world position; may lie outside the image, where drawing is clipped.
public (int px, int py) ToPixel(float x, float z)
Parameters
xfloatzfloat
Returns
- (int px, int py)