terrain hightmap loader

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Markus Bergqvist

terrain hightmap loader

Post by Markus Bergqvist »

when I load a hightmap of for example size 64x64 the terrain node does not create a mesh of 64x64 vertices, it only loads 48x48 (the last patch row and column are missing). When I load a hightmap of size 65x65 it loads all patches but crashes when recalculating LOD.

Is this a bug? If not, how should I load a 64x64 map correctly?

/Thanks
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

it should be a 65x65 heightmap, the heightmaps should be 2^n+1 in width and height.

not sure why it crashes, would need a debug trace or something, if you want, can send me your heightmap and code and i'll test it for you.
Image
Markus Bergqvist

Post by Markus Bergqvist »

ok, i thought it would be 2^n, in the tutorial there is a 256x256 map =)

I tested to switch the tutorial hightmap with mine (65x65) and I run the compiled tutorial, TerrainRendering.exe, included with irrlicht 0.12 source and it crashes when i move the camera in to the center of the terrain. It's not the collision rutines the crashes because i dont move the camera that close and when i remove collisions in my program it crashes anyway.

I think it's something with my hightmap, or the way i created it. The way I did create it was as following: I opened the tutorial hightmap in photoshop, resized canvas to 65x65 and saved it as .bmp 32 bit. Should i do it another way?

Thanks

Here is my hightmap if you want to test it: http://www.kpforum.com/uploaded/mymap.bmp
Markus Bergqvist

Post by Markus Bergqvist »

I did test to resize the tutorial hightmap to 129x129 and it works. 33x33 do not work. Maybe there is a bug in the terrain node.

Anyway, thanks for the response Spintz.
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

Oh, duh, not bug, you have parameters set up bad for that terrain size.

The MaxLOD, I presume, you are leaving at 5, reduce it to 4, with the 65x65 map, or 3 with a 33x33 map and so forth. I should make note of that in the documentation, I will for next time. Sorry didn't think of it earlier.
Image
Markus Bergqvist

Post by Markus Bergqvist »

ah, so thats the problem, well i should have read the documents more in depth :oops:

But then I have a suggestion, if its possible, cant we get a error message insted of a crash? I surpose that the loading rutines only have to check if terrain.size == 33 && MaxLOD == 3 (of course with an algoritm that applies to all sizes but i'am not so good at math so i cant write one).

Thanks for all help!
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

I guess that wouldn't be too hard, I'll add that in
Image
pfo
Posts: 370
Joined: Mon Aug 29, 2005 10:54 pm
Location: http://web.utk.edu/~pfox1

Post by pfo »

Ahha!

So that's why my app was crashing before!

Yeah, you should make a note of that in the documentation and flag an error message when LOD is not set properly.

A better idea might be for the algorithm to set maxLOD based on the dimensions of the map, and / or have the algorithm reject bad maps with an error message. Some of us know how obnoxious it is to have their app crash every 3 seconds b/c the terrain made a mistake :)
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

I'm not going to set it automatically, however, if it's set to high, for a small map, i'll output an error message and lower the setting. However, for large maps, say 513x513, you may still want 5 Levels of detail, or you may want 7, I can't and shouldn't decide that automatically.
Image
delscorcho
Posts: 12
Joined: Tue Aug 23, 2005 10:26 pm

Post by delscorcho »

Hi Spintz,

I'm having an issue that perhaps you can shed some light on. My heightmap is fairly large, 512x512. From what I read here, it needs to be 513x513. Is this correct?

Here's the bigger issue (which may be related). I'm loading my terrain fine, with 5 max LOD. I scale the terrain by 4xz, so I basically have a 2km*2km mesh (1 unit=meter). I then tried to override the LOD values so things are popping in and out so obviously.

0: 500
1: 1000
2: 2000
3: 4000
4: 6000

When I do this, I get a crash at one of the...
RenderBuffer.Vertices[VerticesToRender++] = vertices[...]
... calls. It appears as if VerticesToRender, at that point, is beyond the space available in RenderBuffer.Vertices. I'm going to try and debug it myself, but I'm curious if you've ever had this problem.

Thanks :twisted:

EDIT: While on the subject, I'm making some optimizations to irrlicht, particularly by handling locked vertex buffers, in order to use DrawIndexedPrimitive instead of DrawIndexedPrimitiveUP. Have you tested this with your terrain system at all and seen any performance boosts?
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

Hardware Vertex Buffers will be implemented someday in Irrlicht, I believe. Not putting too much thought or work into that, although it will speed up very large terrains.

Check the bug reports section, I've posted a new terrain node, that fixes that problem as well as many others. You can use Irrlicht-Spintz, until the fixes are implemented into Irrlicht baseline, or grab these files -

http://irrlicht.spintz.com/downloads/CT ... ceneNode.h
http://irrlicht.spintz.com/downloads/CT ... neNode.cpp

EDIT: Links fixed
Last edited by Spintz on Wed Sep 21, 2005 4:18 am, edited 1 time in total.
Image
delscorcho
Posts: 12
Joined: Tue Aug 23, 2005 10:26 pm

Post by delscorcho »

Much appreciated... thanks Spintz
Post Reply