Mesh Terrain to 8bit Height Map

Blitz3D Forums/Blitz3D Programming/Mesh Terrain to 8bit Height Map

Eric(Posted 2004) [#1]
Does anyone have code to take a Terrain, (not a blitz Terrain) And Draw a Height Map based on it?


Pongo(Posted 2004) [#2]
I know I've seen this in the code archives,... take a look there.


aab(Posted 2004) [#3]
could just try it yourself ,taking linepicks, checking the distance between lines begin y and the pickedy() and plotting pixels on an image with a brightness relating to that


DrakeX(Posted 2004) [#4]
or,

img=CreateImage(TerrainSize(t),TerrainSize(t))
SetBuffer ImageBuffer(img)
LockBuffer
For x=0 To TerrainSize(t)-1
	For z=0 To TerrainSize(t)-1
		c=TerrainHeight(t,x,z)*255
		c=(c Shl 16)
		;blitz only uses the red channel for heightmaps, but if you want greys, uncomment the next line
		;c=(c Shl 16)+(c shl 8)+c
		WritePixelFast x,TerrainSize()-z,c
	Next
Next
UnlockBuffer
SetBuffer BackBuffer()


that should work.


Eric(Posted 2004) [#5]
Thanks Drake, But won't that only work with a blitz terrain?

I searched the Board and for some reason can't find the proper code.

I was thinking of iterating through the verts, but not sure how to translate that into a heigth map.

Regards,
Eric


John Blackledge(Posted 2004) [#6]
Yes, I could do woth this as well.

My client wants me to use a very irregular .X mesh terrain which (of course) I would like to convert to a Blitz terrain. And of course the original is not square.

Apart from that, does anyone else have any ideas about mesh to heightmap conversions?


DrakeX(Posted 2004) [#7]
stupid me. i missed the (not a blitz terrain) in your post.

i'd go with what AAB said, with the linepicks. in order to convert it to a heightmap, you'd have to have some kind of min and max height.. ah, just use MeshHeight(). something like this pseudocode:

;load terrain object
;set its pickmode to poly
if meshwidth(t)>meshheight(t) then w#=meshwidth(t) else w#=meshheight(t)
steps=256 ;how detailed the map is
maxheight#=meshheight(t)
;this assumes that the bottom-left corner is at 0,0,0, so all points on the terrain are at least 0 height
for x#=0 to w# step (w#/steps)
    for z#=0 to w# step (w#/steps)
        linepick x#,maxheight#,z#,0,-maxheight#,0
        c=(pickedy()/maxheight#)*255
        ;write color to heightmap image at x,steps-z
    next
next


something like that.


Eric(Posted 2004) [#8]
Yeah Well that didn't work... :(

Step must be a constant...


DrakeX(Posted 2004) [#9]
then rewrite it with a while loop. you're a big boy ;)