Loading

OpenScad Height Maps v0.5

by WilliamAAdams, published

OpenScad Height Maps v0.5 by WilliamAAdams Sep 28, 2011

Description

I needed the ability to quickly generate a tile from a height map. A height map is essentially a grayscale picture. If you think of each of the 'pixel' values representing a 'z' value for a vertex in a mesh, then you can imagine applying those z values, and what you get is a mesh transformed into a 'landscape'.

This thing is just a further refinement of the technique in OpenScad.

Although I am highlighting the technique by applying it to what looks like a landscape, I've also applied it to font rendering as well. There are a couple of ways of doing fonts in OpenScad. One is to use a 'bitmap' and essentially do height mapping, by representing each pixel as a cube.

Another method is to use the font information, and use the outlines to actually draw polygons and linear_extrude() them.

Yet a third way is to use a tool to export the font outlines into a .dxf file, and then load from there with a linear_extrude.

What you can do here is take the font, generate grayscale images of each character, in a format that is essentially OpenScad code. Then apply those images to a mesh, just like a landscape, and you've got extruded fonts!

The cool thing about this generalized technique is that you can use it for anything. The routine gives you absolute control over the size and resolution. So, for example, using the same basic grayscale image, you can print at 48x48 millimeters, with a resolution of 4 facets per millimeter. That would be great if you're printing on a machine with .25mm layer resolution. It would turn out fairly smooth. On the other hand, if you don't want to wait the hours required for that, you can simply change the resolution to be 1mm/facet, and still get a decent print.

The pictures here demonstrate the technique being applied to both terrain and characters.

There are two routines, which can be found in the MeshRenderer.scad file:
shell_extrude_height_map() - To be used when your height map information is represented by single values.

shell_extrude_color_map() - To be used when your height map information is still grayscale, but represented by triplets.

Oh yes, and one of the parameters to this routine: solid=true
That means that while you're prototyping, you can say 'solid=false', and it will simply generate a polygon surface. Then when you're done playing around, you can say 'solid=true', and you'll get a proper 2-manifold solid that you can then press 'F6' on and go take a walk.

I know, it's a lot of words, but look at the pretty pictures!! The 64x64 resolution mountain scene took 5 hours to render. The 48x48 took about 1.5 hours.

NOTE: Although I can easily generate single characters using this technique, actually generating them en masse as shown in the picture, has some problems. The structure ends of not being 2-manifold. I plan to improve the general text handling aspects later. But, the basic height mapping technique will remain the same.

Recent Comments

view all
This gimp export script: thingiverse.com/thing:35373 can also be used to create an Openscad usable surface from a greyscale heightfield.
I'll work on a more cross platform friendly ImageConverter utility. There are tons out there, but none that will do exactly what you need here.

I'll either use Lua or Python, or both...
You can git all the sources here: github.com/Wiladams/OpenScadModels/tree/master/Libraries

You can refer a couple ancestors back to the parent of this current thing and get the .exe from here:
http://www.thingiverse.com/thing:11616

Beware that version of the .exe will generate files that use "rgb_triplets" in the call to image(), and now I use "values" instead. What's in the GIT repos
itory is correct. If it's useful, I'll upload the .exe here, but I'm generally shy about posting .exe for various reasons.

The source code is fairly simply if you're a .net programmer, and simpler still if you're a python or other kind of programmer.

Liked By

view all

License

Public Domain
OpenScad Height Maps v0.5 by WilliamAAdams is licensed under the Public Domain license.

Give a Shout Out

If you print this Thing and display it in public proudly give attribution by printing and displaying this tag. Print Thing Tag
This gimp export script: thingiverse.com/thing:35373 can also be used to create an Openscad usable surface from a greyscale heightfield.
Did you generate that height map in Bryce? :-P
No. That one I got from a tutorial here: lighthouse3d.com/opengl/terrain/index.php3?heightmap

But, you can generate the basic height map using just about any piece of software. In the parent of this thing, I included a simple "ImageConverter.exe" which will take any generic image and create the appropriate height map. It's pretty straight forward.
&
gt;
&
gt;I included a simple "ImageConverter.exe"
&
lt;
&
lt;

Where is this?
You can git all the sources here: github.com/Wiladams/OpenScadModels/tree/master/Libraries

You can refer a couple ancestors back to the parent of this current thing and get the .exe from here:
http://www.thingiverse.com/thing:11616

Beware that version of the .exe will generate files that use "rgb_triplets" in the call to image(), and now I use "values" instead. What's in the GIT repos
itory is correct. If it's useful, I'll upload the .exe here, but I'm generally shy about posting .exe for various reasons.

The source code is fairly simply if you're a .net programmer, and simpler still if you're a python or other kind of programmer.
I'll work on a more cross platform friendly ImageConverter utility. There are tons out there, but none that will do exactly what you need here.

I'll either use Lua or Python, or both...
Top