OpenScad Height Maps v0.5

by WilliamAAdams, published

OpenScad Height Maps v0.5 by WilliamAAdams Sep 28, 2011
0 Share
Download All Files

Thing Apps Enabled

Order This Printed View All Apps



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

Use This Project

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

Thing Statistics

6202Views 3064Downloads


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.

All Apps

3D Print your file with 3D Hubs, the world’s largest online marketplace for 3D printing services.

App Info Launch App

This App connects Thingiverse with Makeprintable, a cloud-based mesh repair service that analyzes, validates and repairs most common mesh errors that can occur when preparing a 3D design file for p...

App Info Launch App

Kiri:Moto is an integrated cloud-based slicer and tool-path generator for 3D Printing, CAM / CNC and Laser cutting. *** 3D printing mode provides model slicing and GCode output using built-in...

App Info Launch App
KiriMoto Thing App

With 3D Slash, you can edit 3d models like a stonecutter. A unique interface: as fun as a building game! The perfect tool for non-designers and children to create in 3D.

App Info Launch App

Honestly, I haven't touched this code in years. Maybe you could make a derivative?

Nice one! I just came across this one, and I found this quite useful!

Though I just found out you haven't used the sfactor for scaling at shell_extrude_height_map(). Maybe you can multiple the sfactor with the z values, something like:

        [x1, y1, z1*sfactor],
        [x1, y2, z2*sfactor],
        [x2, y2, z3*sfactor],
        [x2, y1, z4*sfactor]

Just wanna point it out because the tweak helps me, or may help anyone that came across this one too, do the scaling without touching the image array. :P

This gimp export script: http://www.thingiverse.com/thing:35373http://www.thingiverse.com/thi... can also be used to create an Openscad usable surface from a greyscale heightfield.

OpenSCAD surface Gimp Export Plugin
by ffaat

Did you generate that height map in Bryce? :-P

No. That one I got from a tutorial here: http://www.lighthouse3d.com/opengl/terrain/index.php3?heightmaphttp://www.lighthouse3d.com/op...

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;I included a simple "ImageConverter.exe"

Where is this?

You can git all the sources here: https://github.com/Wiladams/OpenScadModels/tree/master/Librarieshttps://github.com/Wiladams/Op...

You can refer a couple ancestors back to the parent of this current thing and get the .exe from here:

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.

Texture Mapping in OpenScad!

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