I wrote a little C# program to create TER format height fields, but can't seem to get them to appear correctly in Terragen 2.
The border of the heightfield area is highlighted in the preview window, but no matter how I tweak parameters like base height, height scale and elevation points, the terrain is rendered flat.
I'm referencing the file format spec at
http://www.planetside.co.uk/terragen/dev/tgterrain.htmlExample TER file and TGD are attached. The C# code appears below. Once it's working, I'll be glad to share it.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using
System.IO;
namespace Heightmap
{
public class TerFormat
{
// "TERRAGENTERRAIN "
static private readonly byte[] TERRAGEN = new byte[8] { 84, 69, 82, 82, 65, 71, 69, 78 };
static private readonly byte[] TERRAIN = new byte[8] { 84, 69, 82, 82, 65, 73, 78, 32 };
static private readonly byte[] SIZE = new byte[4] { 83, 73, 90, 69 };
static private readonly byte[] SIZEPAD = new byte[2] { 0, 0 };
static private readonly byte[] EOF = new byte[4] { 69, 79, 70, 32 };
static private readonly byte[] ALTW = new byte[4] { 65, 76, 84, 87 };
static public void Write(string filePath, short width, short height, short baseHeight, short scale, short[] elevPoints)
{
if (width != height) throw new Exception("Non-square heightmaps not yet supported. See
http://www.planetside.co.uk/terragen/dev/tgterrain.html");
short sizeMarker = (short)(width - 1);
using (FileStream stream = new FileStream(filePath, FileMode.Create))
{
using (BinaryWriter writer = new BinaryWriter(stream))
{
writer.Write(TERRAGEN);
writer.Write(TERRAIN);
writer.Write(SIZE);
writer.Write(sizeMarker);
writer.Write(SIZEPAD);
writer.Write(EOF);
writer.Write(ALTW);
writer.Write(scale);
writer.Write(baseHeight);
for (int i = 0; i < elevPoints.Length; i++)
{
writer.Write(elevPoints
);
}
writer.Close();
}
}
}
}
}