468,251 Members | 1,372 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,251 developers. It's quick & easy.

2D height map to 3D model?

Hi Folks,

I'm looking to write a Python script that will take a 2D BMP (or
height map) and translate it into a 3D model in OBJ format.

Something of a challenge for me but if it were easy life would be
boring :)

Does anyone know if such a script already exists?
Or any pointers would be appreciated.

Thanks,

PhilC
Jul 18 '05 #1
3 3651
Hi Phil - You don't seem to be getting much in the way of replies so I
thought I would put my 2 cents in ...

PhilC <pc****@philc.net> wrote in message news:<sk********************************@4ax.com>. ..
Hi Folks,

I'm looking to write a Python script that will take a 2D BMP (or
height map) and translate it into a 3D model in OBJ format.

I think you're saying that your input data would be a 2-dimensional
array each element of which would indicate an height above sea level
for that X,Y coordinate (the more I read your original question the
more I doubt my assumption but here goes anyway).

Firstly if you can mangle your data into some format which would be
acceptable as format I suspect that this ...

http://thuban.intevation.org/

.... might do that job.

Assuming that you can't do the mangling (I know I couldn't) have you
seen this ...

http://mayavi.sourceforge.net/

.... and as an instance of the output you might get, this ...

http://mayavi.sourceforge.net/docs/g....html#VIZ-DATA

Another option I came across was this ...

http://www.johnny-lin.com/py_pkgs/Ia...l.html#contour

.... I suspect however that you wanted some output that looked, however
roughly, like an aerial photograph - would be interested to know. I
live in a hilly, rather attractive city and have long wondered about
the possibility of being able to build a model of the land in
software.

Sorry this isn't more help. Maybe you could expand on your needs a
little ?

regards

Richard Shea.

Something of a challenge for me but if it were easy life would be
boring :)

Does anyone know if such a script already exists?
Or any pointers would be appreciated.

Thanks,

PhilC

Jul 18 '05 #2
Thanks Richard,

I was actually thinking of faces but an aerial photograph would be
similar. I'll check through those links and see if they help.

Again my appreciation for your reply.

PhilC

Jul 18 '05 #3
Didn't see the original question, but going from the subject, you want
to generate a 3D mesh from a height field (such as seen in an image).
The algorithm for doing that is fairly straightforward:

rectangles = []
for m in range(dim1-1):
for n in range(dim2-1):
vertices = []
vertices.append( (m,n,heights[m,n]))
vertices.append( (m+1,n,heights[m+1,n]))
vertices.append( (m+1,n+1,heights[m+1,n+1]))
vertices.append( (m,n+1,heights[m,n+1]))
rectangles.append( vertices )

However, that dramatically increases the size of your geometry in memory
(you're storing 12 doubles for almost every data-point). It's easier to
use a format where you define vertices and a separate topology (via
indices into the vertices). Same basic approach works there, you just
have to add m+(n*dim1) to get the index for a corner of the quad. There
you're storing only 3 doubles for each vertex.

If you have a format that allows for triangle/quadrilateral strips, you
can make the rendering far more efficient using them. There you render
(m,n), (m+1,n), (m+1,n+1), (m,n+1), (m+1,n+2), (m,n+2), (m+1,n+3),...
That reduces the size of your index-set as well, but most of the speedup
is going to come from having fewer primitive operations.

Good luck,
Mike

PhilC wrote:
Thanks Richard,

I was actually thinking of faces but an aerial photograph would be
similar. I'll check through those links and see if they help.

Again my appreciation for your reply.

PhilC


--
________________________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://www.vrplumber.com
http://blog.vrplumber.com

Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by delerious | last post: by
17 posts views Thread by Torbjørn Pettersen | last post: by
6 posts views Thread by Stanimir Stamenkov | last post: by
12 posts views Thread by Stanimir Stamenkov | last post: by
3 posts views Thread by Raghavendra | last post: by
3 posts views Thread by TheXenocide | last post: by
6 posts views Thread by jslaybaugh | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.