Creating mesh based on heightmap.

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
JRS
Posts: 45
Joined: Tue Jun 03, 2008 10:00 am
Location: Universität Heidelberg

Creating mesh based on heightmap.

Post by JRS »

Hi,

I'm back again ;)
Special "hi" to JP, because he always answers my questions :)

Now I have another question :P again and again and again...

Is it possible to create a mesh in Irrlicht based on an heightmap?
Again there's my problem with the water in my terrain. As you know, I have a matrix for my terrain, where stands an 1 for "water" and a 0 for "no water".
I created a heightmap out of it and redered the points in arras Tiled Terrain demo.

But how is it possible to tell Irrlicht to take it as a mesh and not a terrain? I know terrain is nothing but a mesh, but if I want to apply

Code: Select all

	node = smgr->addWaterSurfaceSceneNode(mesh->getMesh(0), 3.0f, 300.0f, 30.0f);
I need a mesh and not something that is basically a mesh ;)

So the basic question is: Is it possible to take arras TerrainNode as a mesh?

My plan b:

I had an idea about
smgr->addHillPlaneMesh
and put it into an if loop:
something like:

Code: Select all

if(water=1)
{
addHillPlaneMesh("mywater,(10,10),(100,100),0,10,??,(40,40))
}
else if(water=0)
{
addHillPlaneMesh("mywater,(10,10),(100,100),0,0,??,(40,40))
}
Sorry for the bad pseudo code ;) Hope you'll get it.

Another idea is the do something like:

Code: Select all

for(i=0, i<PointCount,i++)
{
addHillPlaneMesh("mywater,(10,10),(100,100),0,water[i],??,(40,40))
}
I haven't tried it yet. What do you think? Could something like this work?

Thank you!
Regards,
JRS
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

You don't need to use a water surface scene node. What is it you want your water to do? What should it look like?

All the water surface scene node is is a mesh (normally a hill plane mesh, which is just a flat grid) which has waves applied to it by moving the vertices up and down accordinly.

You could do this wave stuff on your terrain node yourself as well if you wanted, just by iterating through its points each frame and updating them.
Image Image Image
JRS
Posts: 45
Joined: Tue Jun 03, 2008 10:00 am
Location: Universität Heidelberg

Post by JRS »

I knew you would be the one answering :P

Thank you.
Ok, I could do this... But could is not CAN ;) Well at least I'll try. But it would be way easier to have a mesh. Is it possible to set multiple terrain Node in one prg?
What I want to do is this:

As you know, I got some satellite data. I read this out, calculated missing heights and wrote everything in a matrix named z[]
Now to add water where water is is the real terrain I read out some other GIS-data named water-poly. What gives me polygons where water should be. I managed to write a "fill polygon" algorithm and so I got a new matrix called water[].
Because the terrain is too flat at some points I think I'll do something like:

Code: Select all

z[]=z[]-water[]
So the terrain will be right.

Now I want to put water in it and so I saw the problem I described.

Some factors that make it difficult:
My terrain is very big (after scaling 2000x2000 coordinate axis)
I'm afraid an animated mesh in this size could kill my fps :(
So I wanted to do it tiled, just as I did with the terrain. My water should look nice ;)
After concerning about fps I think a normal water as it is in example 8 would be enough. But realisitc water would be much better :D

So I wanted to create my terrain and then add water as it is done in example 8 and so I wanted to create a mesh based on my data...
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

not too sure what to suggest, i don't know arras' tiled terrain code so i don't know how it works... it may not even be particularly feasible to get a mesh from it to use as a water node...

maybe arras can comment about this...
Image Image Image
JRS
Posts: 45
Joined: Tue Jun 03, 2008 10:00 am
Location: Universität Heidelberg

Post by JRS »

yeah would be great if arras could comment ;)
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Do you have some kind of a design document for your app made up? t seems that you're still not sure about what the things should look like, and which kind of meta structure you're expecting.
Since sea water is usually always at the same height you can just use one huge water surface to create the sea level. Terrain and sea will intersect, but that's ok, because you'll get the shore for free this way. If you also want to model lakes at non-zero heights you have to create some kind of a mesh which defines the area of that lake. Again, you can overlap with the terrain, unless the terrain will go below the lake's water height very near to the lake's shores. This would make it pretty hard to avoid seams in the world, though, because you cannot easily connect arbitrary meshes without having small space in between.
Allo fthis is laos only necessary if you want to handle water in a special way. If you just use a water texture on top of the mesh surface there's no need at all to do any special stuff for water.
Maybe you can give some more hints on how your app should look like, what the input data looks like, etc.
JRS
Posts: 45
Joined: Tue Jun 03, 2008 10:00 am
Location: Universität Heidelberg

Post by JRS »

Hi,

sorry that I answer this late.
Ok what I want to do:

My terrain is based on some Points. I calculated height for each pixel wrote the height into a matrix. This matrix is named buffer16[].
The I gave this matrix via SetHeight() to the ShTlTerrainSceneNode and tada: I have my terrain.
As far as good.

Now because my terrain isn't very nice I wanted to add some water. There I have data that includes polygons for my water. Based on this data I wrote an algorithm, that fills these polygons.
Now I have a map, which is white, where water should be and black where no water should be.
On step earlier i have a matrix too. There stands an one for "water" and zero for "no water" it's just the same like with my height.

Because my terrain is to flat at some points, I wanted to do "buffer16[]-2*water[]". So that there is a deeper Point, where water should be.
Then, I think, it would be possible to add water just as in example 8. But for this I have to add a mesh what is 2000 x 2000 pixel. And if it is animated, I'm afraid it will kill my fps.

I hope it is one a bit better description :(

If there's no other way, I just want to add a water texture everywhere, water should be. At least a bit better.

Thank you!
jontan6
Posts: 278
Joined: Fri Jun 13, 2008 5:29 pm

Post by jontan6 »

hello,

im not sure if my suggestion is appropriate to your problem. but if you have a heightmap, you can create a mesh in 3ds max based on heightmap.

you can then just export that mesh and load in irrlicht

i found the tutorial here: http://www.delta3d.org/article.php?stor ... =tutorials
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

The size of the water mesh is not really the point, because it can be scaled up automatically, the problem would be the high detail of the water (if required). So if you use a large water plane with high details on it (either the shader water or a water scene node with many polys) which is mostly hidden, you'd get a bad frame rate. The same holds true for detailed water which is completely visible, but that's not avoidable then, because all of it is visible.
So in case you have much more terrain than water it would be better to create several small "lake meshes" which would just work with the same idea, but only cover a smaller area beneath the terrain.
Lowering the terrain inside the sea is also a good idea to avoid zbuffer fighting, moreover it's also quite natural.
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

You can't get mesh out of my terrain since it does not use some structure based on IMesh. You can only get array of vertices and array of indices.

The easiest thing to do would be what hybrid suggest, use either one huge plane to represent "sea" level so everything under is bottom of the sea/lake and everything over is dry land. Or use several such planes on places where you need your water.

Since such plane have just 2 polygoons, you don't have to worry about fps. Unless you owerflood your scene with thousands of them. Of course this have disadvantage of getting flat water surface.You can hoverer use some shader to get it look dynamic.

If you need real dynamic surface there is no easy way. Best would be to have some kind of ShiftingWaterNode which would work in principle the same as my terrain node ...that is shifting visible mesh over large invisible datafield, updating on the way. Or at last repeating itself as it shifts making impression of endlessness. That's something you have to code from scratch of course...

You can even use my terrain node in limited way. Since it allows for dynamic changing of height you can imitate water surface with it comfortably.
Only problem is material ...if you need some transparency or some more advanced effects, you need to change source code. Probably implementing some shader on the way.
Post Reply