Blockland Forums > Modification Help
Perlin Noise
Pew44Six:
--- Quote from: Red_Guy on March 08, 2011, 08:00:24 PM ---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.
--- End quote ---
See, thats what I was wondering, is if you can make a "height field" directly in Torque.
otto-san:
--- Quote from: Pew44Six on March 08, 2011, 08:00:14 PM ---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.
--- End quote ---
minecraft generates terrain with complex algorithms.
Red_Guy:
--- Quote from: Pew44Six on March 08, 2011, 08:01:46 PM ---See, thats what I was wondering, is if you can make a "height field" directly in Torque.
--- End quote ---
meaning - can you make a .bmp file directly from TorqueScript? I highly doubt it.
but theres nothing stopping you from creating bricks
Tom:
--- Quote from: Iban on March 08, 2011, 07:58:30 PM ---1. Badspot has never accepted foreign C++ code.
--- End quote ---
Badspot has used code provided by Ephi.
Destiny/Zack0Wack0:
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: ---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();
}
--- End code ---