New Tiled Terrain Scene Node [works with Irr 1.5]
Hi Arras.. i used your last code... but i-m having another issue.. i-m using a custom player Movement and camera position... (it's the one posted here.. as a WoW player movement..) and i need to create a TriangleSelector for the ShTlTerrainSceneNode.. but i' dont Know how to do it
Another things.. it seems that only loads one square of the Terrain.. maybe it's somethinhg easy to fix ... but i really didn't look at that...
Another things.. it seems that only loads one square of the Terrain.. maybe it's somethinhg easy to fix ... but i really didn't look at that...
A caos world where only the strongest lives, weak is not an option... you must fight.. Nokturna!!
http://nokturna.varholl.com.ar
http://nokturna.varholl.com.ar
-
- Posts: 1029
- Joined: Thu Apr 06, 2006 12:45 am
- Location: Tennesee, USA
- Contact:
Ok it Worked.. but the problem is that the source code i've used also manage the camera... and its really fun.. but the cam gets the gravitation and falls to the infinity
this is the code that uses the triangle Selector in that source code...
I wonder if doing this "MyFloor = ground1->getTriangleSelector()" it could help in anyway i-ve tried without results
Maybe i have to do the same you told me with my camera code??
this is the code that uses the triangle Selector in that source code...
Code: Select all
void SetGround(IrrlichtDevice *dev1,ShTlTerrainSceneNode *ground1){
if(ground1){
MyDevice=dev1;
if(ground1==MyFloorTerrain)return;
MyFloorTerrain=ground1;
MyFloor = MyDevice->getSceneManager()->createTerrainTriangleSelector(ground1, 0);
}
}
Maybe i have to do the same you told me with my camera code??
A caos world where only the strongest lives, weak is not an option... you must fight.. Nokturna!!
http://nokturna.varholl.com.ar
http://nokturna.varholl.com.ar
Sorry for my double post... but i want to post some screenshots of my problem..
What can it be??
My code is like this..
My texture is a jpg of 2048 x 2048 pixels.. and my heightmap is bmp of 256 x 256 pixels...
Thanks in advance!
What can it be??
My code is like this..
Code: Select all
ShTlTerrainSceneNode* terrain = new ShTlTerrainSceneNode(smgr, 255, 255, 1, 100);
terrain->drop();
// load height data from texture
terrain->loadHeightMap("media/mapafinal2.bmp", 10);
// load color map
terrain->loadColorMap("media/nokturna_TX.jpg");
// set detail texture
terrain->setMaterialTexture(0, driver->getTexture("media/detailmap3.jpg"));
// smooth normals
terrain->smoothNormals();
terrain->setMaterialFlag(video::EMF_LIGHTING, false);
Thanks in advance!
A caos world where only the strongest lives, weak is not an option... you must fight.. Nokturna!!
http://nokturna.varholl.com.ar
http://nokturna.varholl.com.ar
monkeycracks >> use stretchTexture(core::vector2d<f32>(scaleX, scaleY));
varholl >> I dont know if Irrlicht TriangleSelector will work with my terrain node. It was not intended to. For placing Sidney on terrain use code monkeycracks was posting here. It places Sidney on the terrain. You may need to use some offset however if origin of Sidney model is in its center and not at its feet (witch seems to be problem on your screenshots):
Howe much offset is depend on your model. Try diferent values to get right one for Sidney. In general it should be distance from origin to lowest wertice of model.
varholl >> I dont know if Irrlicht TriangleSelector will work with my terrain node. It was not intended to. For placing Sidney on terrain use code monkeycracks was posting here. It places Sidney on the terrain. You may need to use some offset however if origin of Sidney model is in its center and not at its feet (witch seems to be problem on your screenshots):
Code: Select all
vector3df pos = playernode->getPosition();
f32 height = terrain->getHeight(pos.X, pos.Z);
pos.Y = height + offset;
playernode->setPosition(pos);
Thanks arras... anyway... my real problem is that the terrain is not loading entirely... i don't know why.. maybe i must create the heightmap in a special way... do you know why could it be?
EDIT:
If you see the screenshots... it seems that the texture is loaded as a plane square... but if i move around... the node get the right height for the terrain... for one reason... it's not working properly and i can't figure out why
2nd EDIT:
Another issue... when i start to walk in the terrain (no matter it's not working i tested it..) when i got position 256, 256... i get this error ..
"Unhandled exception at 0x0041007b in Nokturna.exe: 0xC0000005: Access violation reading location 0xababb37b."
and Vs2005 goes to this method..
Sorry for all this questions.. but i really want to use this tiled terrain...
EDIT:
If you see the screenshots... it seems that the texture is loaded as a plane square... but if i move around... the node get the right height for the terrain... for one reason... it's not working properly and i can't figure out why
2nd EDIT:
Another issue... when i start to walk in the terrain (no matter it's not working i tested it..) when i got position 256, 256... i get this error ..
"Unhandled exception at 0x0041007b in Nokturna.exe: 0xC0000005: Access violation reading location 0xababb37b."
and Vs2005 goes to this method..
Code: Select all
f32 ShTlTerrainSceneNode::getHeight(u32 w, u32 h)
{
return Data(w,h).Height;
}
Sorry for all this questions.. but i really want to use this tiled terrain...
A caos world where only the strongest lives, weak is not an option... you must fight.. Nokturna!!
http://nokturna.varholl.com.ar
http://nokturna.varholl.com.ar
BlindSide >> randomize function work with texture made for demo. Texture is actualy made from 4 tiles, each made of seamles texture. If you would use it with ordinary texture, like one in Irrlicht terrain demo, you would get wrong results.
Randomize function cuts texture in to 4 pieces and put randomly each over diferent tiles.
varholl >> you are using wrong function. One you are using is f32 ShTlTerrainSceneNode::getHeight(u32 w, u32 h) which return height of tile corners. You need to use f32 ShTlTerrainSceneNode::getHeight(core::vector3df pos) which accepts position in 3D (can be your player node) and returns real height of terrain at that place.
Use code monkeycracks was posting.
Randomize function cuts texture in to 4 pieces and put randomly each over diferent tiles.
varholl >> you are using wrong function. One you are using is f32 ShTlTerrainSceneNode::getHeight(u32 w, u32 h) which return height of tile corners. You need to use f32 ShTlTerrainSceneNode::getHeight(core::vector3df pos) which accepts position in 3D (can be your player node) and returns real height of terrain at that place.
Use code monkeycracks was posting.
please, describe what it means exactly in more detail.my real problem is that the terrain is not loading entirely
describe that more too, I dont realy get what your problem is. Do you mean height map texture?it seems that the texture is loaded as a plane square... but if i move around... the node get the right height for the terrain... for one reason... it's not working properly and i can't figure out why
No problem, thats for what this forum is, place to ask questions and get answers. I'm glad to help. Many people helped me the same way.Sorry for all this questions
It works, I am using triangle selectors with your terrain in my project. I will post the code here when I will have some spare time.I dont know if Irrlicht TriangleSelector will work with my terrain node. It was not intended to. For placing Sidney on terrain use code monkeycracks was posting here. It places Sidney on the terrain. You may need to use some offset however if origin of Sidney model is in its center and not at its feet (witch seems to be problem on your screenshots):
Ok.. i'll try itarras wrote: varholl >> you are using wrong function. One you are using is f32 ShTlTerrainSceneNode::getHeight(u32 w, u32 h) which return height of tile corners. You need to use f32 ShTlTerrainSceneNode::getHeight(core::vector3df pos) which accepts position in 3D (can be your player node) and returns real height of terrain at that place.
Well.. let me explain it better (sorry but english is not my mother tong )arras wrote:please, describe what it means exactly in more detail.my real problem is that the terrain is not loading entirely
If i use a heightmap normally... and i set scale to 400,10,400 then my result is a big large and enourmus terrain...
I want to make the same thing with your tiled terrain... but the heightmap is really small.. and i don't know how to make it bigger... if i see your screenshot.. i see a large terrain with a depth view of the horizon... and if you see my screenshot.. is only a small square... i want to make it bigger but don't know how...
Maybe my problem was that getHeight... if i can resolve my last issue this will be resolved to..arras wrote:describe that more too, I dont realy get what your problem is. Do you mean height map texture?it seems that the texture is loaded as a plane square... but if i move around... the node get the right height for the terrain... for one reason... it's not working properly and i can't figure out why
Thanks in advance and hope to explain myself better..
[/quote]
A caos world where only the strongest lives, weak is not an option... you must fight.. Nokturna!!
http://nokturna.varholl.com.ar
http://nokturna.varholl.com.ar
-
- Posts: 1029
- Joined: Thu Apr 06, 2006 12:45 am
- Location: Tennesee, USA
- Contact:
Can anyone post an example, of generating a tiled terrain based on a heightmap and some tiles??? I can't understand how to use it.. and no matter what i get always the same result.. so i'm start thinking i'm the problem, maybe i'm not using it as i should..
A caos world where only the strongest lives, weak is not an option... you must fight.. Nokturna!!
http://nokturna.varholl.com.ar
http://nokturna.varholl.com.ar
monkeycracks >> yes, thats exactly what this node was made for. You have to put all your textures in to one bitmap. In your case rocks and grass. This will result in to detail texture made of subtiles (texture tiles, not terrain tiles). Then you can use seweral functions which manipulate texture UV coordinates to display correct texture tile on tiles you want. Grass on flat tiles, rocks on angled tiles for example. Function which lets you do it is setTileUV().
Of course in case of 2 diferent detail textures (rocks, grass) you want to create transitional textures (texture tiles) so on tiles where rocks and grass meets, they blend smoothly. My TXTBlend tool does make such set of textures out of two diferent ones automaticly: helps.http://irrlicht.sourceforge.net/phpBB2/ ... highlight= You just have to put them together.
In my demo, detail texture is also made of tiles. In this case 4 diferent tiles. They did not represent 4 diferent materials however, rather 4 variants of the same material which are randomly applied ower tiles in order to get some wariability. You may look at randomizeUV() function in someFunctions.h to get idea of howe to cut texture in to tiles and howe to apply them ower individual tiles.
This method of texture blending is quit old and is not without flaws, but it works. (I was trying diferent aproaches but due to some bugs in Irrilicht I kept with this one). In future I plan to change it and make easier.
varholl >> size and shape of your terrain seems to be result of wrong arguments passed in to constructor.
You construct terrain like:
smgr is pointer to scene manager
width and height are dimension of your whole terrain
tilesize is size of single tile, terrain is made of. Tile is square, means its width and height are equal, thats why only one argument.
visiblemeshsize is dimension of part of terrain which will be actualy rendered. Its also square.
So lets consider example:
In this case terrain will be255 x 127 tiles large, but only its portion 50 x 50 tiles will be wisible at any one time. Since tile is 10 x 10 units large, total dimension of whole terrain will be 2550 x 1270 units but only 500 x 500 units large square will be rendered.
Now you want your height map to be loaded: heightmap.bmp is picture 256 x 128 pixels large. Note that we created terrain 255 x 127 tiles large. This means that terrain is exactly the size of height map. As you see size of terrain is one tile less than number of pixels. Thats because height is not applied to tiles itself but rather to its corners. I call those places where tilles meet, spots. And if you would draw simple image of such terrain made of tiles you can see that number of spots on each axis is always one biger than number of tiles.
Second argument is 10. This is scale and controls howe height data from heightmap will be applied on to terrain. Since height is loaded from color value of pixels in heightmap, it can be something between 0-255. 0 represents black, while 255 represent white. Scale 10 means that color 0 will be loaded as height 0 and color 255 will be loaded as height 10. Color 127 would translate in to height 5.
If for example scale would be 1, this would results in to fairly flat terrain since maximum height (black color) will be 1. As we have tiles 10x10 large, this is not a lot.
Size of terrain does not have to be the same as size of heightmap. My node lets you create large terrain and then load its height data from seweral heightmaps. Thats for what loadHeightMap() have those two last arguments. In example above these are 0, 0 and those are coordinates of spot, where you want your heightmap to be loaded.
For example you have 4 heightmaps: heightmap1.bmp, heightmap2.bmp,heightmap3.bmp,heightmap4.bmp. Each is 128x128 pixels large. Now you want terrain 255x255 tiles large to be created out of them:
Hope this helps.
BTW: there is example code on page 5 of this post, which shows howe to create terrain from heightmap.
Of course in case of 2 diferent detail textures (rocks, grass) you want to create transitional textures (texture tiles) so on tiles where rocks and grass meets, they blend smoothly. My TXTBlend tool does make such set of textures out of two diferent ones automaticly: helps.http://irrlicht.sourceforge.net/phpBB2/ ... highlight= You just have to put them together.
In my demo, detail texture is also made of tiles. In this case 4 diferent tiles. They did not represent 4 diferent materials however, rather 4 variants of the same material which are randomly applied ower tiles in order to get some wariability. You may look at randomizeUV() function in someFunctions.h to get idea of howe to cut texture in to tiles and howe to apply them ower individual tiles.
This method of texture blending is quit old and is not without flaws, but it works. (I was trying diferent aproaches but due to some bugs in Irrilicht I kept with this one). In future I plan to change it and make easier.
varholl >> size and shape of your terrain seems to be result of wrong arguments passed in to constructor.
You construct terrain like:
Code: Select all
ShTlTerrainSceneNode* terrain = new ShTlTerrainSceneNode(smgr, width, height, tilesize, visiblemeshsize);
width and height are dimension of your whole terrain
tilesize is size of single tile, terrain is made of. Tile is square, means its width and height are equal, thats why only one argument.
visiblemeshsize is dimension of part of terrain which will be actualy rendered. Its also square.
So lets consider example:
Code: Select all
ShTlTerrainSceneNode* terrain = new ShTlTerrainSceneNode(smgr, 255, 127, 10, 50);
Now you want your height map to be loaded:
Code: Select all
terrain->loadHeightMap("heightmap.bmp", 10, 0, 0);
Second argument is 10. This is scale and controls howe height data from heightmap will be applied on to terrain. Since height is loaded from color value of pixels in heightmap, it can be something between 0-255. 0 represents black, while 255 represent white. Scale 10 means that color 0 will be loaded as height 0 and color 255 will be loaded as height 10. Color 127 would translate in to height 5.
If for example scale would be 1, this would results in to fairly flat terrain since maximum height (black color) will be 1. As we have tiles 10x10 large, this is not a lot.
Size of terrain does not have to be the same as size of heightmap. My node lets you create large terrain and then load its height data from seweral heightmaps. Thats for what loadHeightMap() have those two last arguments. In example above these are 0, 0 and those are coordinates of spot, where you want your heightmap to be loaded.
For example you have 4 heightmaps: heightmap1.bmp, heightmap2.bmp,heightmap3.bmp,heightmap4.bmp. Each is 128x128 pixels large. Now you want terrain 255x255 tiles large to be created out of them:
Code: Select all
ShTlTerrainSceneNode* terrain = new ShTlTerrainSceneNode(smgr, 255, 255, 10, 50);
terrain->loadHeightMap("heightmap1.bmp", 10, 0, 0);
terrain->loadHeightMap("heightmap2.bmp", 10, 128, 0);
terrain->loadHeightMap("heightmap3.bmp", 10, 0, 128);
terrain->loadHeightMap("heightmap4.bmp", 10, 128, 128);
BTW: there is example code on page 5 of this post, which shows howe to create terrain from heightmap.
Last edited by arras on Tue Apr 29, 2008 6:33 pm, edited 1 time in total.