3 ms·
Show HN: LuaCAD – Parametric CAD Scripted in Lua
LuaCAD models solids in Lua rather than the OpenSCAD language, with operator
overloading for CSG (`a + b`, `a - b`, `a * b`).
It ships with a CLI and a desktop app, including a preview area and a text editor.
I've always been a big fan of OpenSCAD, but the SCAD language itself is unfortunately quite cobbled-together and is a very poorly designed programming language.
LuaCAD takes all the good parts of OpenSCAD and combines them with one of the best scripting languages. It has now completely replaced OpenSCAD for me, and I think it provides a better experience than OpenSCAD for all use cases. I'd love to hear any reasons why LuaCAD shouldn't fully replace OpenSCAD!
It’s fully open source and you can find the repo here: https://github.com/ad-si/LuaCAD https://github.com/ad-si/LuaCAD
Tech stack:
- It's implemented in Rust and uses mlua (https://github.com/mlua-rs/mlua https://github.com/mlua-rs/mlua) to execute the Lua code.
- Uses OpenCSG (https://opencsg.org https://opencsg.org) for fast and correct rendering of the 3D models (like OpenSCAD)
- Uses Manifold (https://github.com/elalish/manifold https://github.com/elalish/manifold) to create the manifold triangle meshes
- Native support for all BOSL2 functions (i.e. implemented in Rust for better performance)
- lkjdsklf 2mo agoThe change history on this repository is fascinating
- tolugenius 2mo agoReally interesting! I actually use freecad so I'm use to that layer of the process but I'll check this out. Also good to see the work being done in modeling software these days
- WillAdams 2mo agoIs it able to access the file system and write/read files? I've been doing that via PythonSCAD for my current project https://github.com/WillAdams/gcodepreview https://github.com/WillAdams/gcodepreview and it might be interesting to do a re-write in another language.
- adius 2mo agoYes, it executes in a full fledged Lua environment. So you can do all the things you expect do be able to do with Lua! I’d pick Lua over Python any day, but maybe that’s just me. ;-)
- WillAdams 2mo agoI've had good success w/ using Lua in LuaLaTeX, so hopefully a good fit for me to exercise my programming chops. I think it will be interesting to maintain two parallel versions for comparison/contrast. Thanks!
- manny_rat 2mo agoLove it! OpenSCAD has very painful syntax. Is it possible to easily do bevels/chamfers or does it have the same limitations as OpenSCAD there?
- adius 2mo agoThanks! It natively supports all BOSL2 functions which include a chamfer argument (https://github.com/revarbat/BOSL/wiki#common-arguments https://github.com/revarbat/BOSL/wiki#common-arguments). So that makes it quite straightforward to add chamfers to everything!
- addaon 2mo agoWhich is what separates us from the animals.
- kragen 2mo agoCan you fillet unions? Like, if I union a cube with a smaller cube sticking out of its side, can I make a fillet so that the edge where the two cubes' faces intersect doesn't become a stress concentration point for cracks to start at? This is OpenSCAD's primary weakness from my point of view.
- adastra22 2mo agoQuite easy to add chamfers to everything in the CAD file. But your manufacturing guy is going to strangle you...
- gunalx 2mo agoSo ill strangle myself while the 3d printer goes back and forth.
- fhn 2mo agoDoes this have a web-based playground? I find https://www.pythonscad.org/playground/ https://www.pythonscad.org/playground/ to be nice to try out the project.
- adius 2mo agoAgreed! I’m already working on it, but it’s not quite ready yet. ETA is 1-2 weeks.
- adius 2mo agoI was actually able to get a first version released just now: https://luacad.ad-si.com/playground https://luacad.ad-si.com/playground It's still rather bare bones and won't work well for large models, but otherwise it should be fully functional!
- adastra22 2mo agoIsn't OpenSCAD's limited (non-Turing complete) language a feature?
- adius 2mo agoI'm pretty sure it's Turing complete by now. If it was conceptualized as a limited language and only became a full fledged programming language over time, it would certainly explain all its weird warts. (Here is some more details: https://github.com/ad-si/LuaCAD#why-lua https://github.com/ad-si/LuaCAD#why-lua) I guess 3D modeling is just too complex for a simple, but limited DSL. Lua is easier to use, faster, and more feature-rich. It's one of those rare occasions when a new solution is actually better in every single way.
- adastra22 2mo agoIn the pedantic sense, yes. You can use recursive functions with tail-call optimization, or list comprehensions to emulate a universal Turing machine. But my point is that OpenSCAD's expression purity and one-way compilation model are purposefully limited, and not historical accident: models are a deterministic function of their parameters, subtrees can be cached and reused during preview without invalidation logic, designs diff and merge as text, etc. Sometimes making things "more programmable" is an anti-feature.
- cjbgkagh 2mo agoAFAIK OpenSCAD does not do any meaningful optimizations that are enabled by having a limited DSL, despite that normally being a good reason to do a DSL. And ironically you often have use a general purpose language (python and C++) to do custom optimizations not possible in the DSL.
- adastra22 2mo agoOpenSCAD is garbage and I'm not going to defend it. But I would prefer if a new CAD engine didn't regress.
- 2mo ago
- kiops 2mo ago[flagged]
- psd1 2mo agoA scripting engine is a great feature in cad, you should be proud of your achievement. The reason I'm not personally interested is that i used lisp in AutoCAD in the 00s. What i like most about lua is that it's not php. It's a sane choice, but insipid. https://www.cadtutor.net/tutorials/autolisp/quick-start.php https://www.cadtutor.net/tutorials/autolisp/quick-start.php
- vrinsd 2mo agoHonest question here -- for doing 3D parametric design, is the "programmatic" approach a good thing? If you compare doing a design in LuaCAD to something like Solidworks or ProE, can you get to the end result faster, and easier?
- adius 2mo agoI've tried to get into Solidworks, Fusion, and FreeCAD several times, but every time I come back to programmatic CAD. It just better matches how I think about 3D design I guess. Also, I love that there can't be any hidden state or constraints -everything is fully defined by your code and fully visible. Just give it a try, I guess, and see if it works for your use cases!
- gohash 2mo agoLua is the only language that's born to be embedded — tiny, fast to start, trivial to bind.
- hegjon 2mo agoAwesome! I use both OpenSCAD and BOSL2, looking forward to test it!