Hacker News new | past | comments | ask | show | jobs | submit login
Getting the best out of OpenSCAD (calbryant.uk)
118 points by naggie on Oct 20, 2021 | hide | past | favorite | 59 comments



I've worked a bit in OpenSCAD, and although I really enjoy the programming approach to generating 3D designs, it really is limited when compared to traditional CAD software. Being able to visually align an item, or use even basic commands like offset or fillet, are absent in OpenSCAD. Sure OpenSCAD has it's place, but I think that's in the area of procedural generated shapes, and it's not for 3D part or machine design.

For reference here are some of the items I designed using OpenSCAD:

https://cache.getlazarus.org/images/projects/101/case-and-st...

https://cache.codebot.org/prints/soldering-station.jpg

https://cache.getlazarus.org/images/desktop/soldering-kit-mo...

https://cache.codebot.org/prints/power-supply.jpg

https://cache.getlazarus.org/images/projects/102/control-box...


Try out fogleman/sdf[1]. It is like OpenSCAD in many ways but the distance field model gives you offsets and fillets more easily.

[1] https://github.com/fogleman/sdf


SDFs don't really work for CAD. You cannot even apply an anisotropic scale without making the distance field non-euclidian, which will render the effect of subsequent operations unintuitive. Extrusion along a path is impractical if not impossible in the general case.


As a successful power user making physical objects, I'm wondering how you work without dimensioned drawings?

If you want to learn the distance between two arbitrary points on a part, you need to read the code, and sometimes even do some trig even if you wrote the code. Having markings on the axes is not the same thing: you really want to select two points on a drawing and say "show me this".

This is my biggest wish for OpenSCAD.


> This is my biggest wish for OpenSCAD.

Even better would be a procedural way to "measure" things on models returned by code.

e.g. a method that would return a sorted list of intersection points between a 3D line and a model.

This would be a killer feature for OpenSCAD.

This is all the more sad that the underlying engine (CGAL) does support this feature.


When I first got into 3D printing, I used OpenSCAD for my designs. The fact that objects are described with code made me feel right at home. It made it incredibly easy to make parametric designs.

But later, I did start to feel the limitations. Not having automatic fillet/chamfer was huge. And sometimes, I wanted the ability to measure the distance between two points selected visually to make sure all my math involving offsets was correct.

And as the article mentions, certain shapes end up with a lot of artifacts unless you "render" them, which can take a while. I designed a refillable catnip toy [0] and all the holes in it made the CSG subtraction take ~15 minutes, IIRC. Without rendering though, the opening on the bottom was solid, along with other glitches.

[0] https://www.thingiverse.com/thing:4687159


The trick with holes is to make your negative geometry penetrate past the surface. Meeting exactly on the surface will be too glitchey otherwise with the fast floating-point approximation.

Fillets and chamfers though, yeah. The lack of those drives me away. As Quinn (Blondihacks) says: "Chamfers are what separate us from the animals.", and as This Old Tony says: "When it comes to chamfers, you don't want to cut corners." (And if you don't know who I am quoting, you clearly don't waste enough time watching machinists on Youtube.)


Chamfers can be done by extruding the chamfer shape along a wireframe of the geometry to be chamfered, then subtracting the extrusion from the original geometry. I'm not sure how I'd do fillets in OpenSCAD, though.


You can use a Minkowski sum to give yourself a fillet. I did it once. It worked but was 2x as hard as learning enough Fusion360 to do that whole part and then each design after that is 20% as hard.

I eventually got pretty good at OpenSCAD, but I’d say I now reach for OpenSCAD about 3x/year and everything else is in Fusion.

I wish I’d have switched years ago.


I either live without, or get creative with use of hull, cylinder (including cones), making toroids by radial extruding circles (using the toroid as a cut shape just to get a fillet around a post), or I just open the scad file in freecad, and then apply the fillets in freecad.

It's definitely a weakness in the sales pitch having to work that hard for something you want that often.


All of my scad designs include an o=0.01; or 0.001, and all it's for is for prepending or appending to other values and expressions all over the place so that cuts and joins always overlap at least a little.


As a mechanical designer who has quite a bit of machining experience, I'm the person sounding like a broken record about chamfers when doing design reviews. Blondihacks quote will be going straight into my repertoire of quotes.


Ahhh ToT. Wonder what happened to him, it’s been almost 8 months since he’s released a video.


There was a death in the family, apparently, so he's focusing on family stuff since then.


I thought it was an illness. But yeah, family first.


Before I ran into insurmountable (for me) performance issues with OpenSCAD, I made heavy use of BOSL2[0]. I’d go as far as call it OpenSCAD’s missing standard library. It’s truly sublime.

Fun fact: BOSL2 was written by the same person who made the world’s most 3D printable 3D printer. [1]

[0]: https://github.com/revarbat/BOSL2

[1]: https://github.com/revarbat/snappy-reprap


https://github.com/Irev-Dev/Round-Anything is a helpful library for fillets/chamfers.


I felt the same way and ended up graduating to SolveSpace for shapes I felt were too complex for OpenSCAD. After a few hours learning the new process (create planes and then extrude them) and the shortcut keys, I now exclusively use SolveSpace and my designs have never looked better.


This describes my experience pretty closely. At first OpenSCAD seems like a dream come true: just assemble a few basic shapes with only a few lines of code and you're done!

But things get complicated pretty fast, and as you say, no fillet or chamfer is a terrible limitation. It calls for complex and unpleasant/ugly alternatives (usually, extruding 2D shapes that already have the right angles).

The other big problem with OpenSCAD is that very few true CAD programs are able to import it, and those who do, don't do it well.

So it is fun to play with, but unfortunately it's not really usable for serious work.


Just tried OpenSCAD a couple days ago. The fact that intersection and difference operations often result in z-fighting is extremely frustrating. I read that that it was standard practice to manually account for this by "cutting more than you need". Such bandaid workarounds shouldn't need to exist. It's disappointing because conceptually OpenSCAD is very promising, but fundamental issues like this combined with the overly verbose syntax are holding it back.


Ctrl-F, didn't mention BOSL2

https://github.com/revarbat/BOSL2


I came here to mention BOSL2 and should have Ctrl-F’ed before posting my other comment!


No one has mentioned OpenJSCAD, which is the same idea in Javascript: http://openjscad.azurewebsites.net/

https://github.com/jscad/OpenJSCAD.org/tree/V2

A fairly substantial rewrite is underway, the V2 branch linked above.


I definitely would use version based cad programs with coding options but the pickings are pretty slim for industrial applications aside from the big players. Particularly programs that can be custom built to the users needs.

Solidworks and Catia are often seen as unbeatable for industry but there are so many issues with them, particularly when used in smaller companies or startups. Need Mac support, never. Need multi-threading support, nope never going to implement it. Update the graphics so it doesn't look so ancient and clunky, never. Fusion/autocad are good but are full of bugs and the cloud service is annoying (e.g. I continuously have to delete log files to open the program). Being picky but this stuff shouldn't be hard by now given how long CAD has been around.

Are there any projects using something like rust or c++ to do a build and customise style cad program with versioning? I've tried cadquery, libfive etc. and none really fit the bill.


Is there a good parametric / code based CAD that's good for (amateur) house or garden design, and which runs on linux? I've used openscad in the past for simple parts prototyping, but haven't tried it for 2d work. I always found its preview kind of awkward, so I can't see it exporting or printing particularly well.

I've been learning qcad recently, which is OK, but it really wants you to make extensive use of the mouse. I feel like I could probably be just as productive by typing code and seeing a 2d plot of what I specify. Way back when I used SweetHome3d, which works pretty well for interiors, but (at least when I tried it) didn't have very many tools for exteriors.


Yes, CadQuery: https://cadquery.readthedocs.io/en/latest/intro.html

Think OpenSCAD but based on a proper BREP kernel, so you can express something closer to actual curved surfaces instead of just rasterized approximations.


Something about CadQuery still feels a little off, but it's the only CAD tool I've found that really ticks all the boxes that I want, so I will nonetheless happily give it the prestigious "Least Bad According To Me" award.


My go-to for getting work done has been (and for the foreseeable future will still be) Fusion 360. I can't find a free alternative that is simultaneously batteries included, but also gets out of your way.

It makes me feel like a shill saying something so positive about expensive, proprietary software, but it works _really_ well for my usecases (3D printing, 2.5D and 3D woodcraft carving). Having CAD and CAM in the same package is absolutely killer for me.

In open-source land, though CadQuery is, like you say, the least worst of all the options. I just wish it had a CAM package integrated in there.


Is my understanding correct that all your CAD data is stored in Autodesk cloud servers if you are using Fusion 360?


Yes. I don't really mind this though, as I can export my STEP files (or the full f3d project file, but I rarely ever need to do this).

I hop between multiple computers in my workflow. I do most design on a desktop in my house, and then use the less powerful shop computer to run the CNC or have references up. The auto-syncing of project files "in the cloud" is pretty useful there (in a way that an e.g. sync'd dropbox folder would be clunky to use)


With the free hobbyist version at least, yes that's correct. You can export the files however.


It's such a pity they never released a linux version. It appears to work well in a VM though.


I know what you mean. CadQuery's syntax is weird. Dot-chaining is a terrible interface for nesting commands. ZenCad is the most promising "OpenSCAD but with Python and BREP" project I've seen:

https://mirmik.github.io/zencad/en/index.html


For closed source software, I use OnShape. I've also heard good things about FreeCAD and SolveSpace.


FreeCAD has decent BIM support for A/E/C (using the Arch modules) and works great on Ubuntu. For civil work, use Blender (turn units 'On') and get it setup for GIS with various plugins and pull data from sources like Google Earth.


its really not pretty, but I've written generators for svg and loaded those into Inkscape for composition, etc. (in scheme I guess, but it really doesn't matter..something simple)


I was under the impression that CadQuery sort of obsoletes OpenSCAD. CadQuery uses an more capable geometry kernel: https://github.com/CadQuery/cadquery


The article does mention CadQuery at the end:

"Right now, I’m learning CadQuery which promises to address the shortcomings; it uses a more powerful BREP based CAD engine (OpenCASCADE) combined with the power of Python and inspiration of JQuery, of all things.

"CadQuery is still in semi-early development – it started as a FreeCAD plug-in before becoming independent for the recent 2.0 release.

"Most importantly, the output capability of CADQuery allows for proper STEP, SVG and DXF export, eliminating most of the problems discussed in this article.


>I was under the impression that CadQuery sort of obsoletes OpenSCAD.

I've started to switch to Cadquery from OpenSCAD because it lacks proper fillets and chamfers.

I usually prefer the CSG (arithmetic tree of union/difference/intersection + transforms + base shape leaves) to model 3D objects, as opposed to Cadquery's "draw on 2D surfaces and extrude" approach, but OpenSCAD's lack of fillets / chamfers combined with the "everything is a polygonal mesh" approach of the rendering engine is just too limiting.

Cadquery has a lot of potential (the underlying engine uses a traditional hierarchical NURBS BREP, IIUC), but it also has a lot of shortcomings:

Here are some I've bumped into:

     . very strange "stack-based" model. For complex objects, it's hard to wrap your head around it, and the workflow it forces on you as a user does not always fit your mental model of the object.

     . the underlying hierarchical nature of the object (the BREP) is forcibly hidden from the user, which leads to kafka-esque situations when one wants to e.g. select parts of an object.

     . selecting parts (faces and edges) in a object is a nightmare. cadquery has "selectors", which are a) its own weird little DSL b) very difficult to use on complex shapes c) does not support name-based retrieval: can't label things and get to them later by name.
See this github issue for example: https://github.com/dcowden/cadquery/issues/29

     - the UI (cq-editor) is unusable for real-world work: no perspective rendering, no graduations in ortho views, no way to measure things on the object, no way to examine the BREP, etc ... Generally speaking, the UI is only a visualizer, and does not let you query / inspect the model in any detailed way.

     - fine-grain control over tessellation (conversion to mesh) is lacking.

     - good for modeling mechanical parts / lousy for modeling anything organic-looking

     - importing external models that don't fit the cadquery BREP-based represention is basically impossible.
TL;DR: a nice tool to add to your belt, but not a very mature environment yet, and certainly can't replace OpenSCAD yet.


The link to the GitHub issue is referring to the old archived repository. This should be the link to the most recent discussion: https://github.com/CadQuery/cadquery/issues/371


http://www.implicitcad.org/ is an interesting option if you're frustrated by OpenSCAD's limitations.


It seems to inherit OpenSCAD's biggest limitations, which is that curved surfaces are "rasterized". To make one without perceptible facets, you need to turn the resolution up (which then tanks performance).


They are based on two different algorithms, but both should guarantee a topologically correct solid if implemented correctly.

OpenSCAD is based on constructive geometry, which means the compute complexity scales up mainly along the complexity of the CSG tree which can get very big, but the number of triangles is quite low and independent of the resolution. This is not rasterized but the operation on CSG trees partition the space and the number of regions to consider may grow very quickly and this algorithm is very prone to numerical instabilities, like z-fighting between regions.

ImplicitCAD on the other hand is based on signed distance fields rendered with an pruned octtree marching cube. The algorithm is simpler and more stable numerically. The internal representation is of perfect resolution, but to get a triangulated output you need a number of triangles which grows proportionally to the surface of your object expressed in precision required units. But if you skip this triangulation process, using a custom slicer to generate the toolpaths or a ray tracing renderer to visualize it, you can have perfect resolution for very cheap.

The alternative is BRep, but this is a surface representation which don't bring the same topological guarantees, (like non-self intersection).


That's very cool, thank you for explaining it to me. I'm curious if there's any downsides to such a scheme for representing solids compared to BREP, and the kinds of primitives it supports. E.g how easily can it represent a loft between two arbitrary faces - it's not immediately clear how to represent that with a SDF (but my SDF-foo is admittedly not very strong).

These are questions that I'm sure will be answered by me reading the documentation more closely.


With two arbitrary faces on the same axis (say z), at locations z1 and z2 and the shape of each face being represented by the functions a(x,y) and b(x,y), you can get a loft SDF L(x,y,z) between a and b by the following math (this is not correct syntax for any tool I know but should make it clear what's happening):

if(z<z1) L=a(x,y)

elif(z>z2) L=b(x,y)

else L=((z-z1)/(z2-z1))*a(x,y)+((z2-z)/(z2-z1))*b(x,y)

For way way more info, you might like https://iquilezles.org/www/articles/distfunctions/distfuncti...


Thank you, however, this is but one kind of loft operations done that are common in CAD. Often you want to control the tangency between the connected profiles, or connect profiles that aren’t parallel, or use a center guiderail (arbitrary spline), or use multiple guiderails along specific vertexes on the profiles.

It’s these complex cases that I understand how to approach with a kernel based around face patches, less so how one could achieve it with an SDF


None of those cases are complicated - your SDF can be defined piecewise so you can have as many control points as you want. There's no fundamental difference between SDF and brep in terms of expressiveness - just breps define undirected surfaces and SDFs define volumes. Whether your tool (based on whichever underlying geometry approach) allows you to do what you want to do with them is another story.


This mostly makes sense to me.

I've been looking at the CAD space for a while, and it seems like tools exist at either extreme of the spectrum from "Point, click, drag" UI and "only code to describe the model" UIs. Rhino might be the exception here, but it's very expensive, and doesn't have the parametric / history preserving properties I'm looking for.

I think both of these extremes have drawbacks, so I've been toying with hybrid solutions that involve both a code editor and a 3D interactive pane. The code is still the source of truth, but the system allows you to interactively draw sketches, apply constraints, select faces etc, and then convert your UI interactions back into their equivalent code.

I've been playing with different ways of representing the models (and how that would inform the "language" the model is described with, and the sorts of operations it would support), but that's a whole different problem that I don't want to get mired in, so I'm looking for the simplest thing that gets the job done.

SDFs are looking like a reasonable solution here, but it's hard to look away when OpenCascade is just sitting there...


Awesome! Thanks.. I've been working with implicit modeling for the past half a year but I didn't know there was an "OpenSCAD" equivalent. Seems to work rather well(?)


> http://www.implicitcad.org/ is an interesting option

Mmmh, I'm not so sure.

Is that still maintained?


Do you know whether anyone using these types of tools (like OpenSCAD, CadQuery) in any serious design? By serious I mean, real, industrial use cases (think automotive, defense, aircraft, etc.). Or are these tools mainly targeting hobbyists?


OpenSCAD is very much a hobbyist tool, I'm afraid. It has some internal representation issues (just try generating a STEP to see a few), but there are worse problems. Like the lack of easy fillets and chamfers, or the impossibility of cosmetic surfacing (often very hard even with good tools).

The reality is that the professional market is majority SolidWorks and everyone else fights over the rest. Though Dassault seems to be turning the screws a little too tight these days, so you never know what's in store in the future.


We use those tools for industrial prototyping because we can program those in things like python.

We use it for creating as crappy designs as fast as possible, not getting designers to premature optimization.

For serious design no, we use expensive commercial software for that, once it is clear what the solution is.

For exploring lots of different spaces cheap 3d printer, cheap CNC milling machines and laser cutters are amazing.

We restrict access to serious software for early prototyping because people will try things like super complex organic shapes that require supports or special milling machines instead of machines that cost 100 less money.

That makes time to market so long and a design a competitor could squash the price when he uses cheap alternatives for manufacturing.


> We restrict access to serious software for early prototyping because people will try things like super complex organic shapes that require supports or special milling machines instead of machines that cost 100 less money.

Restricting access to CAD features is a perplexing way to compensate for lack of mechanical engineering skills.


I get it. I see no room to be perplexed since he explained it.

Aside from that, in general, requiring a student to do without a magic tool so they are forced to percieve and understand some fundamental that the magic tool hides, is hardly a new or perplexing concept. Otherwise, you get exactly what he just said, they got.


He's not talking about education, but about professionals producing prototypes.

And designing a part to be manufactured easily with the intended process is a basic mechanical engineering skill.


He certainly is talking about education, at least, exactly as much as I was by using the word "student".

"student" just means "one who studies". It doesn't say anything about what they study or what kind of building or organizational structure they happen to inhabit at the time.

The principle I attempted to articulate is general and applies in any context, including this one.


I used to use gmsh for all of my CSG + meshing work when I was doing simulations. Not done so for many years now though so not sure how it fares these days.


my greatest OpenSCAD tip is to start your files with this prelude:

    $fa = .01;
    $fs = $preview ? 5 : 1;
This will make your maximum facet size 5mm in preview and 1mm in render.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: