Scriptable CAD with familiar syntax

m3dscad is a language for creating 2D and 3D models using the familiar syntax of OpenSCAD with a broader set of primitives.

Examples

In the following examples, we display the result of compiling the code into a triangle mesh.

CSG

You can use difference(), union(), and intersection() to combine shapes.

Loading...
Download STL
difference() {
  cube(2, center=true);
  translate([1, 1, 1]) sphere(1);
}

Path

Create 2D shapes using SVG paths, and extrude 2D shapes into 3D solids.

Loading...
Download STL
linear_extrude(1)
  scale([0.01, 0.01])
  path("
    M0 200 v-200 h200
    a100,100 90 0,1 0,200
    a100,100 90 0,1 -200,0
  z");

Text

Create extruded 3D text from built-in font outlines.

Loading...
Download STL
linear_extrude(0.5)
  rotate(180) union() {
    text("Hello,", size=1.5, valign="center", halign="center");
    translate([0, -2, 0])
      text("World!", size=1.5, valign="center", halign="center");
  }

SDF

Transform and perform booleans on SDFs.

Loading...
Download STL
solid()
  outset_sdf(0.1) // biases the field
  union() {
    translate([0, 0, 0.5])
        cylinder_sdf(r=0.2, h=0.5);
    cube_sdf(1, center=true);
  }

Dual Contour

Round trip through intermediate meshes using dual contouring.

Loading...
Download STL
solid() // back to a solid
  outset_sdf(0.2) // add to the SDF
  mesh_to_sdf() // create an SDF
  dual_contour(delta=0.02) // meshify
  difference() {
    // Imagine some complex shape here which
    // can't be expressed as an SDF directly.
    cube(2, center=true);
    translate([1, 1, 1]) sphere(1);
  }

Metaball

Create smooth blends using metaballs.

Loading...
Download STL
metaball_solid(1, falloff="gaussian") {
  // Sofa body
  cube_metaball([4, 2, 2], center=true);

  // Sofa cutout
  weight_metaball(-1)
    translate([0, 1, 1.3])
    cube_metaball([2.8, 2, 2], center=true);
}