Well I have no idea how to save a height field or create a terrain file, but I did make this just recently:
http://dl.dropbox.com/u/551734/dev/torque/perlin.cs (full code page stretches)
It's based off of this:
http://mrl.nyu.edu/~perlin/noise/ and this:
http://code.zack0wack0.com/jscraft/js/ImprovedNoise.jsHere's the code I used to test it:
function serverCmdPerlinTest(%client,%width,%length,%depth,%iters)
{
if(!%client.isSuperAdmin || !isObject(%client.player))
return;
%ppos = %client.player.getPosition();
%px = getWord(%ppos,0);
%py = getWord(%ppos,1);
%pz = getWord(%ppos,2);
if(!%iters)
%iters = 4;
%perlin = new ScriptObject()
{
class = perlin;
};
%size = %width * %length;
%quality = 2;
%z = getRandom() * %depth;
for(%j=0;%j<%iters;%j++)
{
for(%i=0;%i<%size;%i++)
{
if(%data[%i] $= "")
%data[%i] = 0;
%x = %i % %width;
%y = mFloor(%i / %length);
%data[%i] = %perlin.noise(%x / %quality,%y / %quality,%z) * %quality;
}
%quality *= 4;
}
for(%x=0;%x<%width;%x++)
{
for(%y=0;%y<%length;%y++)
{
%bx = %px + (%x * 2);
%by = %py + (%y * 2);
%bz = %pz + mFloor(%data[%x + %y * %width] * 0.2);
%bpos = %bx SPC %by SPC %bz;
%brick = new fxDTSBrick()
{
position = %bpos;
datablock = brick4xCubeData;
isPlanted = 1;
client = %client;
colorID = 2;
};
%brick.setTrusted(1);
%brick.plant();
%client.brickGroup.add(%brick);
}
}
%perlin.delete();
}
