Assigning HeightMap to Terrain

Blitz3D Forums/Blitz3D Beginners Area/Assigning HeightMap to Terrain

-Rick-(Posted 2006) [#1]
I am creating my Heigtmap pre-game and want to load them into a terrain. Currently the only way I can do this is to save my Heightmap to a .bmp file then use LoadTerrain on it. Is there a simple method to apply my randomly generated Heightmap to a terrain without save/loading or reading each pixel of the heightmap image and altering each corrisponding terrain Y point?

If I use LoadTerrain(HeightMap) I get "failure to load heigtmap" error. The heightmap is there (i've displayed it out to screen and saved it to file directly prior to trying to load it into the terrain) so its not simply a null return error.


WolRon(Posted 2006) [#2]
You do realize that LoadTerrain requires a filename, right? such as LoadTerrain("heightmap.bmp")

Is there a simple method to apply my randomly generated Heightmap to a terrain without save/loading
You can always use the ModifyTerrain command.


-Rick-(Posted 2006) [#3]
I'm interested in knowing if there is a way that avoids having to load in the file. It seems wasteful to create my heightmap, save it to a file, then call it again with a LoadTerrain call.

I also considered using the ModifyTerrain command, but again, rather than setting up a loop to read in all the values and modifying the the terrain 1 point at a time I was wondernig if there was a simpler method. LoadTerrain("hm.bmp") is a 1 step method and bang, its done. It just seems wasteful to me that if I have the image or texture right there on hand I cant apply it to a terrain. I was hoping that there was a command or simple method I wasn't aware of.

Best way to describe what I'm doing is that I've created a terrain and I have a few other images and textures that represent various depths and features underneath. I'm taking "core samples" of my terrain. The terrain is 512,512 and I'm selecting a point and copying a little 10x10 section from that point and of all "layers" below it and then creating a 3d looking Core of the area selected by stacking each layer. Hope that makes sense.

Anyway, just wondering if there was an easier or better method than saving to file and reloading, or going point by point to draw it. Optimally I'd like to just create a new terrain and simply apply an image (heightmap) to it.


octothorpe(Posted 2006) [#4]
Anytime you'd like a 1 step command, write a function. Write your own function to loop through and set all the terrain points (via ModifyTerrain()) using an array (or an image, if you insist) for input values.

There's nothing wrong with "going point by point to draw it," as that's precisely what LoadTerrain() is doing behind the scenes.


-Rick-(Posted 2006) [#5]
?! You guys ... ah nevermind. This feels like when talking to the help desk and they keep asking if the computer is plugged in or if the monitor is turned on.

Thanks for giving me a bit of your time at anyrate.


Ross C(Posted 2006) [#6]
Octophorpe is right though. Create a function like...


Function ApplyHeightMap(terrain,image)



And have your function loop through the bitmap, find the Values of the red channel, And use the modifyterrain command to make the changes.

			RGB1=ReadPixelFast(loop,loop1,TextureBuffer(texture))
			r=(RGB1 And $FF0000)shr 16;separate out the red
			g=(RGB1 And $FF00) shr 8;green
			b=RGB1 And $FF;and blue parts of the color
			a=(RGB1 And $FF000000)Shr 24



That's the code to extract the R, G and B values from the readpixel command. :o)


WolRon(Posted 2006) [#7]
If I use LoadTerrain(HeightMap) I get "failure to load heigtmap" error.
You do also realize that you can overload built-in functions with your own right?

So, for your example above (passing LoadTerrain() an image handle), you can write your own LoadTerrain function (as Ross suggested) that deals with an internal image as opposed to an external one such as you wish.

Of course if you do this, you won't be able to use the original LoadTerrain function any longer...


Wayne(Posted 2006) [#8]
The answer is NO.