CSG
You can use difference(), union(), and intersection() to combine shapes.
Loading...
difference() {
cube(2, center=true);
translate([1, 1, 1]) sphere(1);
}
m3dscad is a language for creating 2D and 3D models using the familiar syntax of OpenSCAD with a broader set of primitives.
In the following examples, we display the result of compiling the code into a triangle mesh.
You can use difference(), union(), and intersection() to combine shapes.
difference() {
cube(2, center=true);
translate([1, 1, 1]) sphere(1);
}
Create 2D shapes using SVG paths, and extrude 2D shapes into 3D solids.
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");
Create extruded 3D text from built-in font outlines.
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");
}
Transform and perform booleans on SDFs.
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);
}
Round trip through intermediate meshes using dual contouring.
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);
}
Create smooth blends using metaballs.
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);
}