Show HN: LuaCAD – 使用 Lua 脚本编写的参数化 CAD
Show HN: LuaCAD – Parametric CAD Scripted in Lua

原始链接: https://luacad.ad-si.com

**LuaCAD** 是一款功能强大的脚本化 CAD 工具,支持使用 Lua 5.4 设计参数化 2D 和 3D 模型。它基于高性能的 Rust 引擎构建,利用 Manifold 实现高效的 CSG(构造实体几何)运算,并提供比 OpenSCAD 更一致、功能更丰富的语法,包括用于几何图形的自然运算符重载。 主要功能包括: * **多格式导出**:可直接将模型导出为 3MF、STL、OBJ、PLY、OFF、AMF 或 SCAD 格式,或渲染为 PNG 图片。 * **高级特性**:全面支持 BOSL2 库,内置文本转几何图形生成功能,并具备强大的网格导入能力(支持 SVG、DXF 和多种 3D 格式)。 * **工作流工具**:包含用于格式转换和文件监视的命令行界面(CLI),以及带有实时 3D 预览功能的 GUI 应用程序 `luacad-studio`。 * **多对象支持**:以 3MF 格式导出的模型可保留各个组件的数据,使切片软件能够将其识别为独立且可移动的部件。 LuaCAD 将编程语言的灵活性与现代 3D 制造的需求相结合,对于追求比传统脚本 CAD 更快速、更易于嵌入的解决方案的用户来说,是一个绝佳选择。

对不起。
相关文章

原文

Scriptable CAD with Lua. Write parametric 2D and 3D models in Lua and export them to 3MF, STL, OBJ, PLY, OFF, AMF, or SCAD, or render them straight to a PNG.

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

LuaCAD Studio previewing the MuSHR racecar model, a 43-part assembly
          of 490,802 triangles, beside the Lua script that builds it

Why Lua?

  • Similar syntax as the OpenSCAD language, but better:
    • More powerful
    • More consistent
    • Faster
    • Easily embeddable
  • Operator overloading for natural CSG syntax (a + b, a - b, a * b)
  • Already used in other CAD software like LibreCAD and Autodesk Netfabb

Example

LuaCAD:

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);
}

Getting Started

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

Or from source, which requires Rust:

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

Both crates vendor their C/C++ dependencies, so no system libraries need to be installed — but a C++ compiler and CMake must be available to build them. luacad builds Manifold and Clipper2; luacad-studio additionally builds OpenCSG, which needs OpenGL development headers (on Debian/Ubuntu: libgl1-mesa-dev, libx11-dev, libxcb1-dev, libxkbcommon-dev, libxrandr-dev, libwayland-dev).

CLI Usage

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 OpenSCAD
luacad watch model.lua output.3mf     # Rebuild on file changes
luacad render model.lua preview.png   # Render to a PNG image
luacad info model.lua                 # Print triangle counts and bounding box
luacad lint model.lua                 # Lint with selene (also takes directories)
luacad run model.lua                  # Execute (side-effects only)

convert and watch infer the format from the output extension; --format <fmt> overrides it, and --via-openscad hands the export to an installed OpenSCAD binary instead of building the mesh with Manifold.

BOSL2

LuaCAD has full support for the Belfry OpenSCAD Library v2, reimplemented in LuaCAD itself, so it renders, previews and exports to a mesh without OpenSCAD or BOSL2 installed:

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 }

Exporting to .scad still writes the BOSL2 call itself, which keeps the exported file as short as the script that produced it.

Text and Imports

text() outlines a system font into a sketch and text3d() extrudes it in one step, so text becomes real geometry rather than SCAD output:

render(text("LuaCAD", { size = 12, halign = "center" }):linear_extrude(2))

import() reads every mesh format LuaCAD writes and returns a solid you can transform and combine like any primitive; SVG and DXF return a 2D sketch instead, ready to extrude.

Supported Export Formats

  • SCAD - OpenSCAD format
  • 3MF - 3D Manufacturing Format
  • STL - Standard Triangle Language for 3D printing
  • OBJ - Wavefront 3D object format
  • PLY - Polygon File Format
  • OFF - Object File Format
  • AMF - Additive Manufacturing File Format

Every value your script returns becomes its own 3MF object, so slicers load them as individually movable parts. Label them with :name(…) to control how they appear in the object list. The other formats cannot express separate objects, so they flatten everything into a single mesh.

联系我们 contact @ memedata.com