2D height map to 3D model?

P

PhilC

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
 
R

Richard Shea

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 said:
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/guide/c919.html#VIZ-DATA

Another option I came across was this ...

http://www.johnny-lin.com/py_pkgs/IaGraph/Doc/manual.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.
 
P

PhilC

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
 
M

Mike C. Fletcher

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
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top