OpenCAMLib (ocl) is a library for creating 3D toolpaths for CNC-machines such as mills and lathes. It is written in C++ and has bindings for Python, Node.js and the browser. At the moment it supports the following algorithms:
The drop cutter algorithm drops a cutter, positioned at a predefined (x,y) location, until it touches the 3D model.
The Push-cutter is used to create a Waterline toolpath that follows the shape of the model at a constant z-height in the xy-plane.
The algorithms listed above can be used with following cutters:
- CylCutter (flat end mill / cylindrical)
- BallCutter (ball end mill / spherical)
- BullCutter (radius end mill / toroidal)
- ConeCutter (tapered end mill / conical)
- CompositeCutter (combinations of the above / compound)
From August 2018 OpenCAMLib is released under LGPL license.
OpenCAMLib provides pre-compiled C++, Node.js and Python libraries for the following platforms and architectures:
| Windows | ia32 / x64 |
| macOS | x86_64 / arm64 |
| Linux | x86_64 / aarch64 |
- The Python library is called
opencamliband is hosted on PyPi (pypi.org), precompiled libraries are available for Python v3.9 up to v3.14. - The Node.js + emscripten library is called
@opencamlib/opencamliband is hosted on npm (npmjs.org), precompiled libraries are available for Node-API v3 and up. - The C++ library is called
libocland is hosted on our Github Releases page.
The Python library (hosted on PyPi) can be installed like this:
pip install opencamlibOn some platforms, pip is called pip3, you might have to run:
pip3 install opencamlibNote that pip / pip3 is will install packages for to the system installation of Python, if you want to install a package in a custom Python installation that is not in your $PATH (for example, the Python which comes with Blender), you can install packages like so:
/path/to/your/custom/python -m pip install opencamlibIf you don't know where Python is, but you have access to it's interpreter (FreeCAD and Blender both have a Python console), you can simply enter this command in there to install OpenCAMLib:
import sys; import subprocess; subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'opencamlib'])The JavaScript library (hosted on npm) works in Node.js and the browser (by leveraging emscripten / WASM) can be installed like this:
npm install --save @opencamlib/opencamlibOr, using yarn:
yarn add @opencamlib/opencamlibNote that it is not 100% feature complete and lacking some functionality still.
Pre-compiled C++ libraries are available on the Github Releases page (https://github.com/aewallin/opencamlib/releases).
This project also installs a OpenCAMLibConfig.cmake, which, if your project uses CMake, allows you to use find_package(OpenCAMLib REQUIRED).
You can see an example of that in use over here: examples/cpp/test/CMakeLists.txt
You can see an example of that in use over here: examples/cpp/test/CMakeLists.txt
Having trouble with a pre-compiled library? Please report it to us. If there are no pre-compiled libraries for your platform or architecture, or want to customize or package opencamlib, this is for you.
OpenCAMLib uses functionality from a library called Boost. Only Boost headers are required; Boost does not need to be compiled.
We provide a install.sh script that helps with installation of dependencies and building OpenCAMLib libraries, you might want to take a look at it first.
You can run ./install.sh --help to look at the available options, or inspect it's source code to find out more.
To compile OpenCAMLib, you need:
- C++ compiler (It should at least support C++ 14)
- Git (This is used for cloning the repository, and the emscripten SDK)
- CMake (At least version 3.18)
- Boost headers
Building the Python bindings additionally requires Python development headers. pybind11 is installed automatically when building the package with pip.
At this time of writing, here are the packages to install:
sudo apt install -y git cmake curl build-essential libboost-dev python3-dev python3-pipbrew install git cmake curl boost pythonInstall
- Visual Studio Build Tools (https://visualstudio.microsoft.com/visual-cpp-build-tools/)
- Git (https://git-scm.com/download/win)
- CMake (https://cmake.org/download/)
By downloading the installers from the internet, or by using your package manager.
The C++ library is the easiest to build, it only depends on Boost's headers. Make sure you have a compiler, git, cmake and Boost installed (or simply download and extract it somewhere).
git clone https://github.com/aewallin/opencamlib
cd opencamlib
mkdir build
cd build
cmake .. -D BUILD_CXX_LIB="ON"
cmake --build . # try make --parallel for a faster build if you have a multi-core machine
cmake --install .When boost is not in a standard location, you can add the -D BOOST_ROOT=/path/to/boost option to the cmake command.
To compile the emscripten library, first download, install and activate it using the following commands:
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
./emsdk install latest
./emsdk activate latestNow you can compile OpenCAMLib like this (make sure to replace the path/to/ sections):
source path/to/emsdk/emsdk_env.sh
git clone https://github.com/aewallin/opencamlib
cd opencamlib
mkdir build
cd build
emcmake cmake \
-D CMAKE_BUILD_TYPE="Release" \
-D BUILD_EMSCRIPTEN_LIB="ON" \
-D USE_OPENMP="OFF" \
-D CMAKE_INSTALL_PREFIX="/path/to/opencamlib/src/npmpackage/build" \
-D BOOST_ROOT="/path/to/boost" \
..
emmake make # try emmake make -j4 for a faster build if you have a multi-core machineNote that USE_OPENMP has been turned off, OpenMP is not supported with Emscripten at the moment
To compile the Node.js library, install the dependencies in src/nodejslib:
cd src/nodejslib
npm installNext, use cmake-js to compile the library:
git clone https://github.com/aewallin/opencamlib
cd opencamlib
mkdir build
cd build
../src/nodejslib/node_modules/.bin/cmake-js \
build \
--directory ".." \
--out "." \
--parallel 4 \
--CD BUILD_NODEJS_LIB="ON" \
--CD USE_OPENMP="ON" \
--CD CMAKE_INSTALL_PREFIX="/path/to/opencamlib/build/Release/$(node --print 'process.platform')-nodejs-$(node --print 'process.arch')" \
--CD BOOST_ROOT="/path/to/boost" \
--config "Release"The Python bindings require Python 3.8 or later, use pybind11, and can be built and installed directly with pip. From the repository root, run:
python -m pip install .pip creates an isolated build environment and installs scikit-build-core and pybind11 as declared build dependencies. Boost headers are still required. To install them with the base dependencies:
./install.sh --build-library python --install-system-deps --install-boost-from-repo --python-pip-install--install-system-deps alone does not install Boost; --install-boost-from-repo
only takes effect with it. Windows uses NuGet headers. Linux release wheels install
boost-devel inside the manylinux container. --install-boost remains the
source archive option.
The package includes a py.typed marker and type information for the opencamlib.ocl extension, so Python type checkers and editors can use the bundled API signatures.
To generate the type stubs, you can use the pybind11-stubgen tool:
python -m pip install pybind11-stubgen
pybind11-stubgen opencamlib -o src/pythonlib/Python subclasses of MillingCutter no longer provide callbacks to native
operations. Use the built-in cutters or implement new cutter behavior in C++.
Please take a look at the examples/ folder on how to use OpenCAMLib.
For each language there is an example named test which calls all of the algorithms.
There is also some API documentation over here: https://opencamlib.readthedocs.io
Compiling OpenCAMLib is unfortunately not very easy and there are many things that can go wrong. Here is a list of common problems and solutions.
This happens a lot, here are some of the reasons why this happens:
You don't have Boost installed.
If you forgot to install boost, go ahead and download Boost from from their website: https://www.boost.org/users/download/ and extract it somewhere. Now, when compiling the C++ or node.js module, add the
-D BOOST_ROOT=/path/to/extracted/boost flag to the cmake .. command, or the.
--boost-prefix /path/to/extracted/boost flag to the ./install.sh command
You installed Boost from Github.
The boost that is hosted on Github does not have the headers yet! To compile those, you should run the following commands:
./bootstrap.sh
./b2 headersYour CMake version has a FindBoost module which is unaware of your Boost's version.
The CMake module that looks for Boost, is usually not aware of the existence of the latest Boost versions.
You can help it by providing the version number of your Boost with the -D Boost_ADDITIONAL_VERSIONS="1.80.0" flag.
Make sure to change 1.80.0 with your version of Boost.
It can also be helpful to enable Boost_DEBUG in the CMake configuration.
To compile OpenCAMLib for other architectures, we recommend the following strategies. Boost headers can be shared across target architectures; no Boost compilation is needed.
Cross compiling on macOS is possible by setting the CMake CMAKE_OSX_ARCHITECTURES flag.
When using the install.sh script, you can use the --macos-architecture flag to accomplish the same thing.
Make sure to take a look at the other --*-architecture flags when cross compiling.
Cross compiling on Windows is possible by using the "Visual Studio" generator (default) and by setting the CMake CMAKE_GENERATOR_PLATFORM flag.
When using the install.sh script, you can use the --cmake-generator-platform flag to accomplish the same thing.
Make sure to take a look at the other --*-architecture flags when cross compiling.
To ensure that compiled libraries work on older linux versions, it has to be compiled with an older Glibc version.
The easiest way to accomplish this is by using Docker, there are images available especially for this purpose.
When using the install.sh script, you can use the --docker-image flag which will make the command run in a container with the given image name.
When cross compiling the C++ library, make sure to use an old Glibc, this is included in the dockcross docker images. For a list of supported architectures, take a look at:
https://github.com/dockcross/dockcross#summary-cross-compilers
Cross compilers for node.js are available here:
https://github.com/prebuild/docker-images
Cross compilers for python are here:
https://github.com/pypa/manylinux#manylinux2014-centos-7-based
- repository https://github.com/aewallin/opencamlib
- PPAs - https://launchpad.net/~iacobs/+archive/ubuntu/cnc/ - https://launchpad.net/~neomilium/+archive/ubuntu/cam - https://launchpad.net/~freecad-community/+archive/ubuntu/ppa - (updated 2012) https://launchpad.net/~anders-e-e-wallin/+archive/ubuntu/cam
- mailing-list http://groups.google.com/group/opencamlib
- IRC-channel #cam on irc.freenode.net
- coding standard (?) http://www.possibility.com/Cpp/CppCodingStandard.html
(generate this with 'tree -dL 2'):
├── docs documentation (not much here yet!) ├── examples c++, emscripten, nodejs and python examples ├── scripts CI scripts for installing and building ocl ├── src │ ├── algo algorithms under development │ ├── common common algorithms and data-structures │ ├── cutters cutter-classes │ ├── cxxlib c++ library cmake config │ ├── deb debian package cmake config │ ├── dropcutter drop-cutter algorithms and operations │ ├── emscriptenlib bindings for emscripten library │ ├── geo primitive geometry classes (point, triangle, stlsurf, etc.) │ ├── nodejslib Node.js library bindings and cmake config │ ├── npmpackage combined Node.js and emscripten wrappers, for publishing to npm │ ├── pythonlib python library bindings and cmake config └── stl STL files for testing

