Loading

OpenSCAD surface Gimp Export Plugin

by ffaat, published

OpenSCAD surface Gimp Export Plugin by ffaat Nov 22, 2012

Description

I've written a gimp python plugin to export the openscad surface format. The pic shows the greyscale height-field and the resultant openscad surface.
This was done to design terrain in gimp and send the tiles to a 3d printer.

Recent Comments

view all

The simplest way is to take the stl into a 3d rendering program and colour it with a black to white gradient along the Z axis. Then set up the camera directly above the surface with a non-perspective projection and render an image at the scale you want.

Note that this plugin scales values from -0.5 to 0.5 (or just under*) which might not be what you are expecting (but is not wrong). Also, it looks like openscad itself adds some kind of raft to the surface. The manual doesn't have much detail on this but something else to be borne in mind.

*Changing the calculation to (pixval-127.5)/255 would produce what one might be expecting.

Having a little trouble. All values are -0.5 Have the latest Gimp and Python installed.

More from 3D Printing

view more

Liked By

view all

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

Instructions

Extract the python file an put it in your gimp plugin directory.
Open a greyscale image in gimp then save it with a ".dat" extension (i.e. "testsurface.dat"

Then use this in openscad comme ca:

surface(file = "testsurface.dat", center=true, convexity = 5);

and scale as needed...

Note that really large surface files will cause openSCAD to die horribly, so it is best to prescale the image before exporting.

I've adjusted the scaling so the 0->255 will map to exactly -0.5 -> 0.5.
Note that the surface routine seems to add a 1 unit high base to the imported surface, so the actual surface rendered will be from -1.5 -> 0.5, so you need to intersect it with a 1 unit high centered box to trim off this base.

Also not that the surface import function does NOT create steps - it generates the triangles vertices based on the pixel values.

This means for a 4x4 image that is a B&W 2x2 checkboard you end up with:
0.5 0.5 -0.5 -0.5
0.5 0.5 -0.5 -0.5
-0.5 -0.5 0.5 0.5
-0.5 -0.5 0.5 0.5

which renders 3x3 units x by y. consisting of two tableaus at -0.5 and two tableaus at 0.5 with sloped surfaces between (which might not be what you were expecting). One of the example images shows this.

Comments

You must be logged in to post a comment.

Richy_T on Jul 30, 2013 said:

Having a little trouble. All values are -0.5 Have the latest Gimp and Python installed.

Richy_T on Jul 30, 2013 said:

Note that this plugin scales values from -0.5 to 0.5 (or just under*) which might not be what you are expecting (but is not wrong). Also, it looks like openscad itself adds some kind of raft to the surface. The manual doesn't have much detail on this but something else to be borne in mind.

*Changing the calculation to (pixval-127.5)/255 would produce what one might be expecting.

Ablapo on Jun 1, 2013 said:

Is there a way back? Using a stl-file to generate a grayscale hight map png-file?

ffaat on Dec 11, 2013 said:

The simplest way is to take the stl into a 3d rendering program and colour it with a black to white gradient along the Z axis. Then set up the camera directly above the surface with a non-perspective projection and render an image at the scale you want.

flurin on Apr 18, 2013 said:

Thank you for the Plug-In. I tested it with Gimp 2.8.3 (OS X 10.8.3), it works.

How-to for use with Customizable Lithopane offline:

First extract the python file "openscad_surface_export.py" and put it in your gimp plugin folder (/Application/Gimp/Content/Resources/lib/glimp/2.0/plug-ins)

1. Open an image in Gimp.
2. Select <img> (right mouse click) Image -> Mode -> Grayscale.
3. Invert Colors: Menu > Colors > Invert.
4. Export the image with a ".dat" extension (i.e. "Surface.dat").

However it doesn't work with the latest Gimp-Version 2.8.4.

ffaat on Apr 18, 2013 said:

Can you be more specific other than "it doesn't work"? Are there any errors, does the file get created incorrectly, or nothing at all?

benbois on Feb 23, 2013 said:

Hi, I tested your plugin with Gimp 2.8.x in Linux, it doesn't work maybe with the new politic of the Saving menu (only Gimp file here).

pyrophreek on Mar 22, 2013 said:

For the newer version of GIMP, you need to use the export command, then select the .dat extension. Works great for me now. A bit of a learning curve to get it working. Awesome plugin!

Top