GhostSCAD: Marrying OpenSCAD And Golang

It’s been at least a couple of months since we’ve seen a different 3D modeling language project, so here’s [Lukasz Janyst] with GhostSCAD: a take on creating OpenSCAD models, using the Go language as the front end, bringing all the delights this modern modular language has to offer (and a few of its own idiosyncrasies.) As [Lukasz] says in the blog, from a programmer’s viewpoint, openSCAD has a number of failings that make it not necessarily hard, just kinda annoying to work with, due to the way the geometry tree works. The OpenSCAD way of working ends up with the programmer requiring knowledge of the internal workings of sub-modules, in order to work at the top level (assembly) which is not an ideal situation from a code reuse perspective.

A programmer would describe this problem as “abstraction leakage” and it doesn’t make modular, reusable coding easy to do without a lot of extra work. [Lukasz] says regarding the example GhostSCAD project, that some parts were modeled in a way that knowledge was needed of some mounting points of sub-modules, but those sub-modules had no way to expose this information to the outside world. GhostSCAD enables the programmer to define parts that expose specific parameters to the world that can be queried, for example, to produce a joining part, or an exploded assembly diagram. These properties can be interpreted without the querying module having any knowledge of the internal structure of the thing it’s working with. GhostSCAD provides a Java3D-like API for defining the geometry tree, which may be familiar to some.

The result of running the Go program is an openSCAD source file, which is not meant to be human-readable but can be subsequently executed and mesh files produced. So why not go check out the GitHub page, and dive into the examples? If you need to learn openSCAD first before you find out its shortcomings, then do check out our guide to mastering openSCAD.

18 thoughts on “GhostSCAD: Marrying OpenSCAD And Golang

  1. As a hobbyist, does OpenSCAD make sense for me? I occasionally use FreeCAD to make simple parts and get them PLA 3D printed. I can program and have superficially played around with OpenSCAD but I’m more curious about the workflow differences, and how larger projects scale.

    Right now its reasonably simple for me to jump into an older FreeCAD project and get up to speed in a few minutes by looking around and be ready to make incremental changes. In OpenSCAD how does that scale out? Would I need to read the code and comprehend the steps and be at the mercy of the comments I left at 3am on a Sunday morning or is there some other way?

    I personally think programming/scripting based CAD tools are actually handier than mouse and sketching based ones (at least for us folks who are better at writing code than moving mouse around)

    1. Well personally i never managed the learning curve of freecad, whilst getting to the point of beeing able to solve all my needs with openscad was fairly easy and straightforward… Especially for someone who is mouse-handicapped, openscad ist a real blessing

    2. As a hobbyist i enjoy openscad very much. especialy the fact how fast i was able to learn it. you know how to code HTML? OpenSCAD will be rather easy concept for you to learn after seeing few examples and learning how to search stuff in official documentation wiki.

      You just learn few commands and can already start to create. Which is easier than learning whole complexity of GUI.

      Readability of existing designs is obviously dependent on how elegantly the openscad code is written. Eg. do you predefine some dimensions and constants at the top and then base all your coordinates based on that? or do you just put random coordinates and dimensions all throughout the code so that resizing/moving one component will become annoying task because there are lots of places where you need to update something. do you use parametric submodules or just copypaste the openscad code to 10 different places with minor tweaks? all these things affect readability and reusability of your openscad model.

    3. The way you need to think to do FreeCAD ‘properly’ so your models don’t just break here and there in a massive cascade every time you want to tweak something in one place isn’t hugely different from OpenSCAD, you might find you like it more than FreeCAD, you may find it less.

      For myself I tend to create a quick and dirty sketch on paper, then FreeCAD for a complex model to really figure out all the relationships between the parts. Then you start again knowing how everything interacts with everything else to set the right parameters – at which point OpenSCAD or more FreeCAD isn’t hugely different. And because I’m also more occasional CAD than frequent I tend to stick with FreeCAD – text based languages you have to really learn the language, recall its grammar, commands and their spellings or spend a long time with the English to OpenSCAD dictionary – a GUI based system prompts you a little more, so its enough to remember a few fundamental rules and hover over a button or two till you find the right one.

      But if you are just making small little widgets and don’t need to worry about parametric adjustments of everything the power of instant visual and just bodging a new shape or adding a fillet onto a face/vertex that FreeCAD (or any GUI cad gives) is hard to beat. For that sort of use I can’t see why anybody would choose OpenSCAD, as its power really is in creating very powerfully customisable parametric models, not quickly creating something ‘right enough’.

      1. I think OpenSCAD is the easiest cad there is, because what language there is, is very consistent. Want a solid object? Ez. Want it hollow? Stick a smaller one inside it. Want a horizontal tube? Rotate it 90 degrees.
        I am a programmer, so I can think procedurally.

        1. Any not purely artistic CAD user has to be be able think that way…

          But to use OpenSCAD you need to have learned its grammar and dictionary, and then as a programmer remember it really isn’t really a programming language so you will have to work around its oddities. That is a lot of memorising arcane drivel to use it efficiently that you just won’t achieve if you don’t use it enough.

    4. having spent a LOT of time and effort making models and scenes in POVray, openSCAD was very easy for me to get into

      I do miss POVray features, especially patterns, it would be great to print models with “patterns”

      sometimes a model needs weathering, rust effects

    5. If you are coming from any sort of coding experience do yourself a favor and just start with JSCad. Otherwise, you will learn your way to the limits of what OpenSCAD is designed to do and find yourself constantly fighting against OpenSCAD’s designers’ intended limits of what OpenSCAD is for and wishing you hadn’t committed the time to learning it in the first place.

      1. CadQuery (a python library) is another solid option for those hoping to avoid the pitfalls of OpenSCAD. I haven’t used JSCad before but, glancing through some documentation and examples, it looks extremely similar in functionality.

        A bonus for JSCad is that it seems to be easier to get rolling (a free, seemingly fast online playground!) with it than CadQuery, which has a mildly annoying install process if you want an interactive editor. Looking at JSCad’s github, it would also be easy to integrate it or a subset of it into a website, which is dope.

        I may have to give it a try for my next project.

    6. For me – a programmer – personally OpenSCAD is an abomination of the highest order.
      I have no problem whatsoever with ‘functional-like’ approach to some things in it (which is a common complain for many) but there are these following problems each of which is a complete deal breaker to me:
      – There are no structs or namespaces! You have to prefix or suffix everything and then painstakingly refactor it when you need to include something new with a clashing name. I’ve seen desperate attempts to deal with this using arrays and various constants with indexes.
      – Modules are disjunct from functions.
      – You can’t take a reference to module or pass module into another module or function. OpenSCAD is NOT a functional language. It’s disfunctional mess.
      – Modules not only don’t return a geometry, they can’t return anything! You need to get dimensions of a sliced geometry? Nope. Oh, you know how to calculate it by hand? Well OpenSCAD says f u.. you won’t get anything from children() and you can return anything anyway…. Just duplicate the whole module structure with functions if you need values.

      The last thing is such a massive problem that the arguably biggest and most commonly used OpenSCAD library the DUPLICATES every module using function and every module generated geometry with function generated VNF, region, or path.. so you can use them in computations.

      1. Exactly!

        So I have a nice library that given a fastener type and size calculates all the dimensions and draws it. I let the end user pick their fastener type and size then subtract object this from my object to get a nice bolt hole. So far so good. Now I want to position something else a calculated distance from that hole that varies based on the size of the clearance needed.

        In a sane language I could take that already drawn object and look at something like a .head_diameter property. Or, really since I let the user pick from multiple fastener types maybe it’s not a bolt with a head. So perhaps a .required_clearance property that is part of some parent fastener class.

        Well, as Grawp would say, OpenSCAD says FU, you are going to need a separate function that redundantly calculates that information for not good reason other than we don’t want to be a “programming” language.

        Or.. you write a nightmare of spaghetti and numerically indexed matrices just to avoid re-calculating things.

        Like I said. Skip OpenSCAD and start with JScad if you are already a progammer.

    7. go with what works for you. i think generally the people who will enjoy openscad’s strengths and not resent its weaknesses will feel love at first sight. if you have to ask the question, the answer is probably no. it’s pretty niche in that it’s not friendly to beginners unless they really wanted a scripting language in the first place, and it’s not particularly appealing to people who already know a few different cad tools because they’ll always be aware of its real limitations.

      but i love openscad :)

  2. After a somewhat brief go with FreeCAD, I abandoned it, moved to OpenSCAD and have lived happily ever after. My simple test case involved putting a 1/4 inch diameter hole at a location specified by the center cooirdinates. I never could figure out how to get FreeCAD to do that for me. It is straightforward and obvious with OpenSCAD and I was able to cross that goal in minutes.

    Now as to whether layering Go (aka golang) on top of OpenSCAD is a win, I cannot say. I would prefer python actually. Not that I love python, quite the opposite, but I do know it and can get things done with it. Go on the other hand Is just another doggone imperative language that I am hoping to avoid ever learning.

    1. Try CadQuery, it’s a Python library that uses the opencascade CAD kernel. I’ve found it works quite well. Someone above recommended JSCad, which looks very similar, but with JS (unsure what kernel it is under the hood).

      I try freeCAD about once a year, always thinking that my memories must be blowing things out of proportion. Every time I realize that any tool fancier than a simple extrude is inherently broken (my latest try involved sweeping a simple profile, which output an overlapping solid model impossible to do further operations to), and even building with simple extrudes requires a major shift from traditional 3D CAD workflows due to the topological naming problem. Throw in a clunky UI and mediocre keybinds and it’s a tool that makes me want to tear my hair out every time I use it.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.