MCPcopy Index your code
hub / github.com/ad-si/LuaCAD

github.com/ad-si/LuaCAD @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
950 symbols 2,512 edges 64 files 172 documented · 18%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

LuaCAD

Solid 3D CAD modeling with Lua.

Write parametric 2D and 3D models in Lua and export them to 3MF, STL, OBJ, PLY, OFF, AMF, or SCAD.

Screenshot of LuaCAD Studio app

LuaCAD embeds Lua 5.4 in a Rust engine that evaluates CSG operations directly (via Manifold) or generates SCAD code for external rendering.

Installation

Via Crates

cargo install luacad  # CLI for running and converting LuaCAD scripts
cargo install luacad-studio  # GUI desktop app with live 3D preview

From source

Requires Rust.

git clone https://github.com/ad-si/LuaCAD.git
cd LuaCAD
make install

Usage

CLI

luacad convert model.lua output.3mf   # Convert to 3MF
luacad convert model.lua output.stl   # Convert to STL
luacad convert model.lua output.scad  # Export as SCAD for OpenSCAD
luacad watch model.lua output.3mf     # Rebuild on file changes
luacad run model.lua                  # Execute (side-effects only)

Studio

luacad-studio

Desktop app with a code editor and 3D viewport. Edit Lua code on the right, see the model update on the left.

Example

my_cube = cube { size = { 1, 2, 3 } }

function my_sphere(radius)
  return sphere({ r = radius }):translate(5, 0, 0)
end

model = my_cube + my_sphere(2)

render(model)

Equivalent OpenSCAD:

module my_cube() {
  cube(size=[1,2,3]);
}

module my_sphere(radius) {
  translate([5,0,0]) sphere(r = radius);
}

union() {
  my_cube();
  my_sphere(2);
}

More examples in the examples/ directory.

Check out the website to see all supported features!

For easier usage, LuaCAD has full support for the Belfry OpenSCAD Library v2. You can use its functions like this:

bosl.cuboid { {40, 40, 40}, rounding = 2 }
bosl.regular_prism { 5, r = 10, h = 25 }
bosl.spur_gear { circ_pitch = 5, teeth = 20, thickness = 5 }

Why Lua?

The OpenSCAD language is limited and has several issues:

  • Confusing functions vs modules
  • Weird variable scoping
  • Not a well establised programming language
    • Bad editor support
    • Limited documentation
    • Limited libraries
    • Bad error messages
    • Bad performance

Therefore, a real programming language should be used and it should ideally be interpreted and have good operator overloading support

  • Julia - Too complex
  • Python - Too slow and while easy to get started, hard to master

Lua is a better fit:

  • Well-established, embeddable language
  • Operator overloading for natural CSG syntax (a + b, a - b)
  • Consistent semantics and good performance
  • Similar syntax to OpenSCAD's language
  • Already used in other CAD software (LibreCAD, Autodesk Netfabb)

Supported Export Formats

Roadmap

  • [ ]

Related

Other CAD software with programmatic model creation:

History

The initial Lua implementation was done by Michael Lutz at thechillcode/Lua_CAD. The project was later rewritten in Rust.

Core symbols most depended-on inside this repo

generate_scad
called by 94
crates/luacad/src/scad_export.rs
run_lua_scad
called by 86
crates/luacad/src/lua_engine.rs
table_get_f64
called by 59
crates/luacad/src/bosl.rs
is_empty
called by 59
crates/luacad/src/export.rs
write_indent
called by 59
crates/luacad/src/scad_export.rs
end
called by 48
OpenCSG/src/batch.cpp
begin
called by 39
OpenCSG/src/batch.cpp
lua_val_to_f32
called by 39
crates/luacad/src/geometry.rs

Shape

Function 622
Method 215
Class 87
Enum 26

Languages

Rust63%
C++26%
TypeScript10%

Modules by API surface

crates/luacad/src/lua_engine.rs125 symbols
website/highlight.min.js99 symbols
crates/luacad/src/bosl.rs79 symbols
crates/luacad/src/export.rs67 symbols
crates/luacad/tests/example_snapshots.rs52 symbols
crates/luacad-studio/src/scene.rs37 symbols
crates/luacad/src/scad_export.rs34 symbols
OpenCSG/src/glad/src/gl.cpp31 symbols
crates/luacad/src/render.rs30 symbols
crates/luacad-studio/src/csg_tree.rs29 symbols
OpenCSG/src/channelManager.cpp24 symbols
crates/luacad-studio/src/camera.rs19 symbols

For agents

$ claude mcp add LuaCAD \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact