Author Topic: Perlin Noise  (Read 2011 times)

Hiya.

I was wondering if it's possible to generate a terrain map with Perlin Noise in Torque. And if it is, how to do it.

Thank ya :D

I also have the source of Torque 3D if I need to do some kind of C++ stuff.

I also have the source of Torque 3D if I need to do some kind of C++ stuff.
Blockland runs on TGE, so that won't work.

As far as I know, TGE doesn't even have height map importing at all.

so no.

1. Badspot has never accepted foreign C++ code.
2. Why can't you just do a cubescape?
« Last Edit: March 08, 2011, 08:00:01 PM by Iban »

1. Badspot does not accept has never accepted foreign C++ code.
2. Why can't you just do a cubescape?

Well I was wondering how Minecraft worked with terrain, and I figured Perlin noise had something to do with it, and I just don't know how to actually do Perlin Noise in Torque. Also I was planning on doing this with T3D, just as a practice project.

if you can make a height field (gray-scale bitmap) - then you can import that into the mission editor.  or if you want it made out or bricks -- just write your own .bls file and load that.

if you can make a height field (gray-scale bitmap) - then you can import that into the mission editor.  or if you want it made out or bricks -- just write your own .bls file and load that.
See, thats what I was wondering, is if you can make a "height field" directly in Torque.

Well I was wondering how Minecraft worked with terrain, and I figured Perlin noise had something to do with it, and I just don't know how to actually do Perlin Noise in Torque. Also I was planning on doing this with T3D, just as a practice project.
minecraft generates terrain with complex algorithms.

See, thats what I was wondering, is if you can make a "height field" directly in Torque.
meaning - can you make a .bmp file directly from TorqueScript?  I highly doubt it.

but theres nothing stopping you from creating bricks

Tom

1. Badspot has never accepted foreign C++ code.
Badspot has used code provided by Ephi.

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.js

Here's the code I used to test it:
Code: [Select]
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();
}

That is pretty awesome. So I don't even need a height field to make terrain?

That is pretty awesome. So I don't even need a height field to make terrain?
You're making a mod for a game about building with bricks and your first instinct is to use something other than bricks to make terrain.

What.

-snip-
Man, now I'm interested in Perlin Noise.

I'm probably going to mess around with this a bit in the near future.  :cookieMonster:

You're making a mod for a game about building with bricks and your first instinct is to use something other than bricks to make terrain.

What.
Also I was planning on doing this with T3D, just as a practice project.