Openscad: Warp 3d Surface To Fit Onto Another Shape

Discussion in 'Software and Applications' started by andrewthommo, May 18, 2017.

Tags:
  1. andrewthommo
    andrewthommo Member
    Can OpenSCAD warp a (basically flat) 3D map to fit the outside or inside of a shape like a tube?

    To expand, say there is a surface based on a grayscale image of a landscape's topography. Is there a command (or easy way I missed) to curve the flat (bottom) side to the inside or outside of a tube?

    I guess it'd be possible to carve the surface into N pieces, translate each one to the internal or external radius of the tube, then create an union of the slices. For the outside of the tube, it would be necessary to expand the width of each slice slightly to avoid creating steep 'canyons' appearing between each pair of slices.

    But I'm hoping there is a more elegant approach I've not thought of, or an existing command I've missed.
     
  2. lkcl
    lkcl New Member
    hi andrew, openscad is basically a thin wrapper onto libcsg. anything that CSG can do, openscad can do... and CSG is *not* designed to do anything but the most absolute basic of shapes and transformations: cubes, cylinders and *CORRECT* polygons defined by points and a list of triangles is your lot.

    openscad's language is basically... not very good. it's a macro language, it's nowhere near NP-complete and i don't really understand why people don't understand that actually writing directly in openscad is... painful shall we say. that having been said the amount of people who *have* worked with it is so huge, and the advantages of using e.g. git revision control and standard software development and management practices has been a *huge* advantage, such that there are an enormous amount of libraries and work out there which you can take advantage of.

    i can't stand not having a proper programming language (i tried for example to pass parameters to openscad only to discover that it doesn't even have proper variable "scopes"!) so i now work with pyopenscad and have done for years, now.

    pyopenscad (and the associated pyopenscadobj that i wrote) basically has *all* the power of python as a proper modern OO programming language - objects, functions, modules, lambda calculus, exceptions, yield and way more - but outputs SCAD files in effect as "machine code".

    with that in mind it's funny because i *just* completed an improvement to a program that i wrote called polysurface.py - an improvement that i've been planning for six years now - which can be used to do exactly what you asked for: morph one shape into another.

    the key improvement that i made was that polysurface now takes just a "sheet thickness" (where it previously took a vector parameter) and it automatically calculates the orthogonal vectors at each and every point. run "python polysurface.py" and then view the resultant test.scad file to see what it can do. it's really cool, and complicated as hell :)

    http://hands.com/~lkcl/eoma/kde_tablet/3dcase/morph.py

    that example starts from a circle then progressively goes through a series of rectangles: it's designed to demonstrate "morphing" for a fan nozzle for a 3D printer:

    Untitled.png

    now, please bear in mind: splines are not really designed to be circular, so this example by no means perfect, but it demonstrates the point and is "good enough" for what i need. if i *really* wanted it to be "perfect" then what i would do is create 4 separate sets of splines, one for each quadrant of the object (with a special focus on making sure that each spline covered the corner of the rectangles), then join them all back together afterwards

    [and, as it's all in python, that's really easy to do].

    but one of the simple things that i will definitely be doing is to add a couple of extra sets of points to the list.... *after* spline-processing... one at the top and one at the bottom in the "perfect" shapes that i want. the only tricky bit is making sure that the number of points in the "perfect" shapes is the same as in the auto-generated spline(s).

    in short: you're expecting a pre-stone-age flint axe to be able to create a.. .a... GT40 supercar :)

    anyway go grab these files and you can get started:
    http://hands.com/~lkcl/eoma/kde_tablet/3dcase/spline.py
    http://hands.com/~lkcl/eoma/kde_tablet/3dcase/polysurface.py
    http://hands.com/~lkcl/eoma/kde_tablet/3dcase/pyopenscad.py
    http://hands.com/~lkcl/eoma/kde_tablet/3dcase/pyopenscadobj.py
    http://hands.com/~lkcl/eoma/kde_tablet/3dcase/pyscadutil.py

    that should do the trick.

    so, to do what you want, you'd basically start from where you should be starting: a proper programming language, one that can read in the images, process them, and then use pyopenscad and polysurface.py to auto-generate a scad file.
     
    andrewthommo likes this.
  3. andrewthommo
    andrewthommo Member
    Thanks for the info.! That OpenSCAD cannot do this task 'out of the box' completely ..fails to surprise me.

    Though I am a bit busy at the moment, but will definitely look more closely into Python etc. in the near future.
     
  4. lkcl
    lkcl New Member
    it can "do" it... but you're down to manipulating at the polygon level... and openscad (because it's not an NP-complete language) simply cannot read any file-format that the (specific and directly-CGAL-related and *only* CGAL-related) available functions support.

    so if you want to read say a bmp file or any other arbitrary greyscale file-format... you can flat-out forget it.

    openscad *really is* a simple "shim" onto libCGAL (not CSG, sorry).

    so if you *happen* to have a way to programmatically convert... saaay... a grayscale bmp into a 2D DXF file *THEN* you can *CONSIDER* using the "2D to 3D extrude" function.

    but note the caveat "programmatically convert"... because openscad *can't handle it*.

    but even if you did that, you could only extrude 2D DXF to 3D object as a *flat* object.

    basically what you're asking for is pretty esoteric for any 3D CAD/CAM program to do: it really does require some sort of programming, and if you were going to start from anywhere i'd start from python. you *might* be able to find a series of snippets of random code on the internet which you can piece together. start with a google search "python convert greyscale image to 3D raised coordinates" or something like that.

    i know for a fact that there do exist programs out there where people have done this sort of thing. i have a friend whose son got into trouble for telling "lies" at school about a "magic box" that his daddy had which could make pictures come to life. at the next parent's "show and tell" weekly meeting, the teacher got a reprimand as his father brought in his 3D printer and created bas-relief coloured 3D prints of the children's pictures....
     
  5. stonysmith
    stonysmith Well-Known Member Moderator
    Let me see if I can dig up my old code.. I built a routine years ago to map a jpg of the moon onto a sphere.
    I think there might also be a routine in Blender to do a "bump map offset" or something like that.