Hacker News new | ask | show | jobs
by zackangelo 655 days ago
I wonder if the prevalence of coding LLMs will bring renewed attention to code-based modeling systems like OpenSCAD. It seems much easier to get them to generate code vs. translating into GUI interactions or modifying some other internal state directly.
4 comments

I’m sure there will be some value, especially as the LLM systems become capable of doing more of the work, but as a professional robotics engineer with a focus on mechanical engineering, OpenSCAD just cannot perform appropriately to serve as a primary CAD platform for professional mechanical design. Parametric GUI based design has so many advantages, a key one being that you can click on a feature and change it easily.
I think both approaches have merit, I find the ability to have proper libraries/functions (such as "place M4x8 socket head countersunk bolt here") is really nice, though I'm faster with the click&change approach for exploratory design.

However the thing holding OpenSCAD back is the fact it is CSG (basically booleans on primitives) which is just not good enough for non-trivial parts. More interesting tool is cadquery[1] which uses the OpenCASCADE b-rep kernel. Still not as powerful as commercial offerings sadly, but at least on the right path to get there.

[1] https://cadquery.readthedocs.io/en/latest/

I've been using build123d (based on cadquery) quite a bit and I really like it. I still use solidworks for simulations, drawings, and most fillet operations - because it turns out that doing fillets right is very non-trivial.

Code-cad is great because you get exactly what you put in, but sometimes it can feel like starting with a bucket of logic gates instead of a microcontroller.

I've had "test LLM's with code-cad" on my todo list for a while, as I think it has the possibility of greatly accelerating the production of the additional part libraries that I'd need to able to make more regular use of it.

Been trying to install cadquery on a mac (M1) but ouch, not easy, and not working yet.
FWIW conda-forge packages cadquery and it's dependencies, including on macOS-arm. So micromamba/mamba/conda can easily be used to install it. build123d is being worked on.
Great, thanks! I'll give it a try. Brew -> pip -> cadquery was a dead end for me.
Got it running, thanks again!
I've been wondering the same thing. Unfortunately, I've found that GPT-4o is much less good at OpenSCAD than it is at Python.

It feels totally untrained on the step-by-step logic you need to build things in a programatic way. This is likely a problem with not having enough training data.

There is a version of OpenSCAD which adds support for Python:

https://pythonscad.org/

That said, the bigger problem is that OpenSCAD is easy for things which are tractable to being described mathematically, and that the boundary for what can be described is one's fluency with mathematics --- once one gets beyond those things which can be described by rectangles, cylinders, and spheres, it gets quite difficult, and getting elements aligned often requires trigonometry (I have one backburner project which needs for me to get up-to-speed on conic sections).

There are some folks who are able to write code to generate point clouds or polygons which describe surfaces (see recent discussions on the OpenSCAD mailing list), but not many, and there isn't much such code, and when it does exist, it tends to be quite special purpose and hard to apply to different shapes.

It would help if there was a Bézier curve primitive in OpenSCAD, or better some support for a NURBS surface as a core primitive so folks wouldn't constantly be rolling their own options.

Surely all of GitHub is “enough training data”
Well, there's a lot less OpenSCAD on GitHub than Python. At first glance maybe a few orders of magnitude less.

But the bigger problem is (probably) not the lack of code, but the lack of good tutorials and well-documented libraries. And since there's no package manager (https://github.com/openscad/openscad/issues/3479) there's still no agreed-upon way to reuse code between projects.

All this is conjecture, of course. LLMs are mysterious beasts.

OpenSCAD is frequently written on the same level as M4 macro language, or assembly code with no comments. If you're bad at mental arithmetic and bad at keeping track complicated internal state, like LLMs are, you will have a bad time.

Look at the one linked below, for instance. This is from the official OpenSCAD repo, examples folder. There is no way for even an experienced programmer to understand and successfully modify that code without sitting down with a pencil and paper and doing arithmetic and geometry for half an hour.

https://github.com/openscad/openscad/blob/master/examples%2F...

The low amount of training data is definitely one issue, but I also think back to the SCAD I've written and it's not got very much in the way of English prompt-friendly text in it to "guide" the LLM towards using it.

Arguably, this might mean I don't comment the code "enough", but in other languages, the variable names and overall structure seem to carry a lot of that for the human programmer and also in a way that guides an LLM towards effectively using it. I don't know much about how LLM's work internally either, but I picked a random SCAD file of mine and I don't know how it'd be found to create a PCB spacer with generous clearance for an M3 screw.

  $fn = 90;
  
  outer = 4.5 + 1.6;
  inner = 4.5;
  h = 13.5;
  
  //round = true;
  //square = true;
  hex = true;
  
  if (square)
    difference() {
      cube(size = [outer, outer, h]);
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
      translate([(outer-inner)/2, (outer-inner)/2,-0.05]) cube(size = [inner, inner, h+1]);
    }

  if (round)
    translate([0,15,0])
      difference() {
        cylinder(d = outer, h = h);
        translate([0,0,-0.05]) cylinder(d = inner, h = h+1);
      }

  if (hex) translate([0,30,0])
    difference() {
      cylinder(d = outer*1.25, h = h, $fn=6);
      translate([0,0,-0.05]) cylinder(d = inner*1.25, h = h+1, $fn=6);
    }
that's right; and its pretty good at this, see here a few examples : https://git.osr-plastic.org/osr-plastic/osr-ai/src/branch/ma... (check the generated scad files). For some reason, chat-gpto looses relations, after 5+ parts within an assembly.
You could model the internal state like code that a LLM can work with.