Convert Figma logo to code with AI

openscad logoopenscad

OpenSCAD - The Programmers Solid 3D CAD Modeller

7,586
1,272
7,586
966

Top Related Projects

24,091

This is the official source code of FreeCAD, a free and opensource multiplatform 3D parametric modeler.

G-code generator for 3D printers (RepRap, Makerbot, Ultimaker etc.)

6,408

3D printer / slicing GUI built on top of the Uranium framework

3,418

Open Source toolpath generator for 3D printers

Quick Overview

OpenSCAD is an open-source software for creating solid 3D CAD (Computer-Aided Design) models. It uses a script-based approach, allowing users to create complex 3D models using a functional programming language. OpenSCAD is particularly popular in the 3D printing community for its precision and parametric design capabilities.

Pros

  • Parametric modeling: Easily create and modify designs using variables and mathematical expressions
  • Text-based scripting: Allows for version control and easy sharing of designs
  • Cross-platform compatibility: Available for Windows, macOS, and Linux
  • Free and open-source: Accessible to all users without licensing costs

Cons

  • Steep learning curve: Requires programming knowledge, which may be challenging for beginners
  • Limited GUI: Lacks a traditional point-and-click interface for model manipulation
  • Slower rendering: Complex designs may take longer to render compared to other CAD software
  • Limited organic modeling: Better suited for mechanical parts than organic shapes

Code Examples

  1. Creating a simple cube:
cube([10, 20, 30]);
  1. Creating a cylinder with rounded edges:
$fn = 100;
cylinder(h = 30, r1 = 10, r2 = 5);
  1. Creating a parametric gear:
module gear(num_teeth, gear_height, gear_diameter) {
    pitch = gear_diameter / num_teeth;
    tooth_depth = pitch / 2;
    cylinder(r = gear_diameter/2 - tooth_depth, h = gear_height, $fn = num_teeth*2);
    for (i = [0:num_teeth-1]) {
        rotate([0, 0, i * 360 / num_teeth])
        translate([gear_diameter/2 - tooth_depth, 0, 0])
        cube([tooth_depth*2, pitch/2, gear_height]);
    }
}

gear(20, 10, 50);

Getting Started

  1. Download and install OpenSCAD from the official website: https://openscad.org/downloads.html
  2. Launch OpenSCAD and create a new file
  3. Write your OpenSCAD code in the editor pane
  4. Press F5 to render the preview
  5. Press F6 to render the final model
  6. Export your model as STL or other supported formats using File > Export

Competitor Comparisons

24,091

This is the official source code of FreeCAD, a free and opensource multiplatform 3D parametric modeler.

Pros of FreeCAD

  • Offers a more traditional CAD interface with parametric modeling
  • Provides a wider range of tools and features for complex designs
  • Supports multiple file formats for import and export

Cons of FreeCAD

  • Steeper learning curve for beginners
  • Can be resource-intensive for complex models
  • May have stability issues with certain operations

Code Comparison

OpenSCAD:

cube([10, 20, 30]);
translate([5, 10, 15]) sphere(r=5);

FreeCAD Python:

import FreeCAD as App
import Part

doc = App.newDocument()
box = Part.makeBox(10, 20, 30)
sphere = Part.makeSphere(5)
sphere.translate(App.Vector(5, 10, 15))
doc.addObject("Part::Feature", "Box").Shape = box
doc.addObject("Part::Feature", "Sphere").Shape = sphere

OpenSCAD uses a declarative programming approach, while FreeCAD allows for more traditional CAD operations and scripting through Python. OpenSCAD is generally simpler for basic geometric shapes, while FreeCAD offers more flexibility for complex designs and parametric modeling.

G-code generator for 3D printers (RepRap, Makerbot, Ultimaker etc.)

Pros of PrusaSlicer

  • User-friendly interface for 3D printing preparation
  • Advanced slicing algorithms optimized for various printers
  • Extensive support for different materials and print settings

Cons of PrusaSlicer

  • Limited 3D modeling capabilities
  • Less flexibility for creating parametric designs
  • Focused on slicing rather than object creation

Code Comparison

PrusaSlicer (C++):

void TriangleMesh::repair()
{
    if (!this->repaired) {
        this->stats().volume = 0.;
        this->stats().number_of_parts = 0;
        this->repaired = true;
    }
}

OpenSCAD (C++):

Value ValuePtr::operator!() const
{
    if (this->type() == Value::Type::BOOL) {
        return !this->toBool();
    }
    return false;
}

While both projects use C++, PrusaSlicer focuses on mesh processing and slicing algorithms, whereas OpenSCAD emphasizes scripting and parametric modeling functionality.

6,408

3D printer / slicing GUI built on top of the Uranium framework

Pros of Cura

  • User-friendly GUI for 3D printing preparation
  • Advanced slicing features and support generation
  • Extensive printer compatibility and customization options

Cons of Cura

  • Limited 3D modeling capabilities
  • Less flexibility for parametric design

Code Comparison

OpenSCAD (Declarative 3D modeling):

module gear(teeth = 20, radius = 5) {
    circle(r = radius);
    for (i = [0:teeth-1]) {
        rotate(i * 360 / teeth) translate([radius, 0, 0]) square([2, 1]);
    }
}

Cura (Python-based plugin system):

from UM.Extension import Extension
from UM.Logger import Logger

class MyPlugin(Extension):
    def __init__(self):
        super().__init__()
        Logger.log("d", "MyPlugin initialized")

OpenSCAD focuses on programmatic 3D modeling, while Cura's code primarily deals with slicing and printer management. OpenSCAD uses its own declarative language for creating 3D models, whereas Cura employs Python for extending functionality and managing the slicing process.

3,418

Open Source toolpath generator for 3D printers

Pros of Slic3r

  • Specialized for 3D printing slicing, offering advanced features for print optimization
  • User-friendly GUI for easier operation and visualization of 3D models
  • Actively maintained with frequent updates and improvements

Cons of Slic3r

  • Limited to slicing functionality, not suitable for 3D modeling
  • May have a steeper learning curve for advanced settings and configurations
  • Less flexibility in terms of customization compared to OpenSCAD

Code Comparison

OpenSCAD (Declarative modeling):

cube([10, 10, 10]);
translate([5, 5, 5]) sphere(r=5);

Slic3r (Configuration example):

bed_shape = 0x0,200x0,200x200,0x200
z_offset = 0

Summary

OpenSCAD is a 3D modeling software using a scripting language, while Slic3r is a 3D printing slicer. OpenSCAD offers more flexibility in creating complex 3D models programmatically, whereas Slic3r excels in preparing 3D models for printing with optimized settings. The choice between the two depends on the specific needs of the user: OpenSCAD for modeling, Slic3r for print preparation.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

GitHub (master) CircleCI (master) Coverity Scan

Visit our IRC channel

What is OpenSCAD?

OpenSCAD is a software for creating solid 3D CAD objects. It is free software and available for Linux/UNIX, MS Windows and macOS.

Unlike most free software for creating 3D models (such as the famous application Blender), OpenSCAD focuses on the CAD aspects rather than the artistic aspects of 3D modeling. Thus this might be the application you are looking for when you are planning to create 3D models of machine parts but probably not the tool for creating computer-animated movies.

OpenSCAD is not an interactive modeler. Instead it is more like a 3D-compiler that reads a script file that describes the object and renders the 3D model from this script file (see examples below). This gives you, the designer, complete control over the modeling process and enables you to easily change any step in the modeling process or make designs that are defined by configurable parameters.

OpenSCAD provides two main modeling techniques: First there is constructive solid geometry (aka CSG) and second there is extrusion of 2D outlines. As the data exchange format for these 2D outlines Autocad DXF files are used. In addition to 2D paths for extrusion it is also possible to read design parameters from DXF files. Besides DXF files OpenSCAD can read and create 3D models in the STL and OFF file formats.

Contents

Getting started

You can download the latest binaries of OpenSCAD at https://www.openscad.org/downloads.html. Install binaries as you would any other software.

When you open OpenSCAD, you'll see three frames within the window. The left frame is where you'll write code to model 3D objects. The right frame is where you'll see the 3D rendering of your model.

Let's make a tree! Type the following code into the left frame:

cylinder(h = 30, r = 8);

Then render the 3D model by hitting F5. Now you can see a cylinder for the trunk in our tree. Now let's add the bushy/leafy part of the tree represented by a sphere. To do so, we will union a cylinder and a sphere.

union() {
  cylinder(h = 30, r = 8);
  sphere(20);
}

But, it's not quite right! The bushy/leafy are around the base of the tree. We need to move the sphere up the z-axis.

union() {
  cylinder(h = 30, r = 8);
  translate([0, 0, 40]) sphere(20);
}

And that's it! You made your first 3D model! There are other primitive shapes that you can combine with other set operations (union, intersection, difference) and transformations (rotate, scale, translate) to make complex models! Check out all the other language features in the OpenSCAD Manual.

Documentation

Have a look at the OpenSCAD Homepage (https://www.openscad.org/documentation.html) for documentation.

Building OpenSCAD

To build OpenSCAD from source, follow the instructions for the platform applicable to you below.

Prerequisites

To build OpenSCAD, you need some libraries and tools. The version numbers in brackets specify the versions which have been used for development. Other versions may or may not work as well.

If you're using a newer version of Ubuntu, you can install these libraries from aptitude. If you're using Mac, or an older Linux/BSD, there are build scripts that download and compile the libraries from source. Follow the instructions for the platform you're compiling on below.

For the test suite, additional requirements are:

Getting the source code

Install git (https://git-scm.com/) onto your system. Then run a clone:

git clone https://github.com/openscad/openscad.git

This will download the latest sources into a directory named openscad.

To pull the various submodules (incl. the MCAD library), do the following:

cd openscad
git submodule update --init --recursive

Building for macOS

Prerequisites:

  • Xcode
  • automake, libtool, cmake, pkg-config, wget, meson, python-packaging (we recommend installing these using Homebrew)

Install Dependencies:

After building dependencies using one of the following options, follow the instructions in the Compilation section.

  1. From source

    Run the script that sets up the environment variables:

     source scripts/setenv-macos.sh
    

    Then run the script to compile all the dependencies:

     ./scripts/macosx-build-dependencies.sh
    
  2. Homebrew (assumes Homebrew is already installed)

     ./scripts/macosx-build-homebrew.sh
    

Building for Linux/BSD

First, make sure that you have git installed (often packaged as 'git-core' or 'scmgit'). Once you've cloned this git repository, download and install the dependency packages listed above using your system's package manager. A convenience script is provided that can help with this process on some systems:

sudo ./scripts/uni-get-dependencies.sh

After installing dependencies, check their versions. You can run this script to help you:

./scripts/check-dependencies.sh

Take care that you don't have old local copies anywhere (/usr/local/). If all dependencies are present and of a high enough version, skip ahead to the Compilation instructions.

Building for Linux/BSD on systems with older or missing dependencies

If some of your system dependency libraries are missing or old, then you can download and build newer versions into $HOME/openscad_deps by following this process. First, run the script that sets up the environment variables.

source ./scripts/setenv-unibuild.sh

Then run the script to compile all the prerequisite libraries above:

./scripts/uni-build-dependencies.sh

Note that huge dependencies like gcc, qt, or glib2 are not included here, only the smaller ones (boost, CGAL, opencsg, etc). After the build, again check dependencies.

./scripts/check-dependencies.sh

After that, follow the Compilation instructions below.

Building for Windows

OpenSCAD for Windows is usually cross-compiled from Linux. If you wish to attempt an MSVC build on Windows, please see this site: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Building_on_Windows

To cross-build, first make sure that you have all necessary dependencies of the MXE project ( listed at https://mxe.cc/#requirements ). Don't install MXE itself, the scripts below will do that for you under $HOME/openscad_deps/mxe

Then get your development tools installed to get GCC. Then after you've cloned this git repository, start a new clean bash shell and run the script that sets up the environment variables.

source ./scripts/setenv-mingw-xbuild.sh 64

Then run the script to download & compile all the prerequisite libraries above:

./scripts/mingw-x-build-dependencies.sh 64

Note that this process can take several hours, and tens of gigabytes of disk space, as it uses the https://mxe.cc system to cross-build many libraries. After it is complete, build OpenSCAD and package it to an installer:

./scripts/release-common.sh mingw64

For a 32-bit Windows cross-build, replace 64 with 32 in the above instructions.

Building for WebAssembly

We support building OpenSCAD headless for WebAssembly w/ Emscripten, using a premade Docker image built in openscad/openscad-wasm (which also has usage examples)

#### Browser

The following command creates build-web/openscad.wasm & build-web/openscad.js:

./scripts/wasm-base-docker-run.sh emcmake cmake -B build-web -DCMAKE_BUILD_TYPE=Debug -DEXPERIMENTAL=1
./scripts/wasm-base-docker-run.sh cmake --build build-web -j2

openscad/openscad-playground uses this WASM build to provide a Web UI with a subset of features of OpenSCAD.

[!NOTE] With a debug build (-DCMAKE_BUILD_TYPE=Debug), you can set C++ breakpoints in Firefox and in Chrome (the latter needs an extension).

Standalone node.js build

The following command creates build-node/openscad.js, which is executable (requires node):

./scripts/wasm-base-docker-run.sh emcmake cmake -B build-node -DWASM_BUILD_TYPE=node -DCMAKE_BUILD_TYPE=Debug -DEXPERIMENTAL=1
./scripts/wasm-base-docker-run.sh cmake --build build-node -j2
build-node/openscad.js --help

[!NOTE] With a debug build (-DCMAKE_BUILD_TYPE=Debug), you can set C++ breakpoints in VSCode + Node (needs an extension).

Compilation

First, run cmake -B build -DEXPERIMENTAL=1 to generate a Makefile in the build folder.

Then run cmake --build build. Finally, on Linux you might run cmake --install build as root.

If you had problems compiling from source, raise a new issue in the issue tracker on the github page.

This site and it's subpages can also be helpful: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Building_OpenSCAD_from_Sources

Once built, you can run tests with ctest from the build directory.

Note: Both cmake --build and ctest accepts a -j N argument for distributing the load over N parallel processes.

Running CI workflows locally

  • Install circleci-cli (you'll need an API key)

    Note: we also use GitHub Workflows, but only to run tests on Windows (which we cross-build for in the Linux-based CircleCI workflows below). Also, act doesn't like our submodule setup anyway.

  • Run the CI jobs

    # When "successful", these will fail to upload at the very end of the workflow.
    circleci local execute --job  openscad-mxe-64bit
    circleci local execute --job  openscad-mxe-32bit
    circleci local execute --job  openscad-appimage-64bit
    

    Note: openscad-macos can't be built locally.

  • If/when GCC gets randomly killed, give docker more RAM (e.g. 4GB per concurrent image you plan to run)

  • To debug the jobs more interactively, you can go the manual route (inspect .circleci/config.yml to get the actual docker image you need)

    docker run --entrypoint=/bin/bash -it openscad/mxe-x86_64-gui:latest
    

    Then once you get the console:

    git clone https://github.com/%your username%/openscad.git workspace
    cd workspace
    git checkout %your branch%
    git submodule init
    git submodule update
    
    # Then execute the commands from .circleci/config.yml:
    #    export NUMCPU=2
    #    ...
    #    ./scripts/release-common.sh -snapshot -mingw64 -v "$OPENSCAD_VERSION"