Mesh Terrain to 8bit Height Map
Blitz3D Forums/Blitz3D Programming/Mesh Terrain to 8bit Height Map
| ||
Does anyone have code to take a Terrain, (not a blitz Terrain) And Draw a Height Map based on it? |
| ||
I know I've seen this in the code archives,... take a look there. |
| ||
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 |
| ||
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. |
| ||
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 |
| ||
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? |
| ||
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. |
| ||
Yeah Well that didn't work... :( Step must be a constant... |
| ||
then rewrite it with a while loop. you're a big boy ;) |