Skip to content
forked from elalish/manifold

Geometry library for topological robustness

License

Notifications You must be signed in to change notification settings

yetigit/manifold

 
 

Repository files navigation

codecov twitter

Users

OpenSCAD, IFCjs, Grid.Space, and OCADml have all integrated our Manifold geometry kernel! Why? Because its reliability is guaranteed and it's 1,000 times faster than other libraries. See our usage and performance discussions for all the latest and to add your own projects & analyses.

For example, here is a log-log plot of Manifold's performance vs. earlier OpenSCAD geometry backends:

If you like OpenSCAD / JSCAD, you might also like ManifoldCAD - our own solid modelling web app. Our WASM is not GPU-accelerated, but it's still quite fast and a good way to test out our Manifold library.

A metallic Menger sponge

Manifold

API Documentation | Algorithm Documentation | Blog Posts | Web Examples

Manifold is a geometry library dedicated to creating and operating on manifold triangle meshes. A manifold mesh is a mesh that represents a solid object, and so is very important in manufacturing, CAD, structural analysis, etc. Further information can be found on the wiki.

This is a modern C++ library that Github's CI verifies builds and runs on a variety of platforms. Additionally, we build bindings for JavaScript (manifold-3d on npm), Python, and C to make this library more portable and easy to use.

We have four core dependencies, making use of submodules to ensure compatibility:

  • graphlite: connected components algorithm
  • Clipper2: provides our 2D subsystem
  • GLM: a compact vector library
  • Thrust: Nvidia's parallel algorithms library (basically a superset of C++17 std::parallel_algorithms)

What's here

This library is fast with guaranteed manifold output. As such you need manifold meshes as input, which this library can create using constructors inspired by the OpenSCAD API, as well as more advanced features like smoothing and signed-distance function (SDF) level sets. You can also pass in your own mesh data, but you'll get an error status if the imported mesh isn't manifold. Various automated repair tools exist online for fixing non manifold models, usually for 3D printing.

The most significant contribution here is a guaranteed-manifold mesh Boolean algorithm, which I believe is the first of its kind. If you know of another, please open a discussion - a mesh Boolean algorithm robust to edge cases has been an open problem for many years. Likewise, if the Boolean here ever fails you, please submit an issue! This Boolean forms the basis of a CAD kernel, as it allows simple shapes to be combined into more complex ones.

To aid in speed, this library makes extensive use of parallelization, generally through Nvidia's Thrust library. You can switch between the CUDA, OMP, TBB, and serial C++ backends by setting a CMake flag. Not everything is so parallelizable, for instance a polygon triangulation algorithm is included which is serial. Even if compiled for CUDA, the code will still run without a GPU, falling back to the serial version of the algorithms. The WASM build is serial-only for now, but still fast.

Look in the samples directory for examples of how to use this library to make interesting 3D models. You may notice that some of these examples bare a certain resemblance to my OpenSCAD designs on Thingiverse, which is no accident. Much as I love OpenSCAD, my library is dramatically faster and the code is more flexible.

Building

Only CMake, a C++ compiler, and Python are required to be installed and set up to build this library (it has been tested with GCC, LLVM, MSVC). However, a variety of optional dependencies can bring in more functionality, see below.

Build and test (Ubuntu or similar):

git clone --recurse-submodules https://github.com/elalish/manifold.git
cd manifold
git apply thrust.diff
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON .. && make
test/manifold_test

CMake flags (usage e.g. -DMANIFOLD_USE_CUDA=ON):

  • MANIFOLD_USE_CUDA=[<OFF>, ON]: Provides Nvidia GPU parallelization, requires CUDA Toolkit and its nvcc compiler.
  • MANIFOLD_PAR=[<NONE>, OMP, TBB]: Provides multi-thread parallelization, requires libomp-dev or libtbb-dev.
  • MANIFOLD_EXPORT=[<OFF>, ON]: Enables GLB export of 3D models from the tests, requires libassimp-dev.
  • MANIFOLD_DEBUG=[<OFF>, ON]: Enables internal assertions and exceptions.
  • BUILD_TEST_CGAL=[<OFF>, ON]: Builds a CGAL-based performance comparison, requires libcgal-dev.

The build instructions used by our CI are in manifold.yml, which is a good source to check if something goes wrong and for instructions specific to other platforms, like Windows.

WASM

To build the JS WASM library, first install NodeJS and set up emscripten:

(on Mac):

brew install nodejs
brew install emscripten

(on Linux):

sudo apt install nodejs
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
./emsdk install latest
./emsdk activate latest
source ./emsdk/emsdk_env.sh

Then build:

cd manifold
mkdir buildWASM
cd buildWASM
emcmake cmake -DCMAKE_BUILD_TYPE=Release .. && emmake make
node test/manifold_test.js

Python

The CMake script will build the python binding pymanifold automatically. To use the extension, please add $BUILD_DIR/tools to your PYTHONPATH, where $BUILD_DIR is the build directory for CMake. Examples using the python binding can be found in bindings/python/examples. To see exported samples, run:

sudo apt install pkg-config libpython3-dev python3 python3-distutils python3-pip
pip install trimesh
python3 run_all.py -e

Run the following code in the interpreter for python binding documentation:

>>> import pymanifold
>>> help(pymanifold)

For more detailed documentation, please refer to the C++ API.

Contributing

Contributions are welcome! A lower barrier contribution is to simply make a PR that adds a test, especially if it repros an issue you've found. Simply name it prepended with DISABLED_, so that it passes the CI. That will be a very strong signal to me to fix your issue. However, if you know how to fix it yourself, then including the fix in your PR would be much appreciated!

About the author

This library was started by Emmett Lalish. I am currently a Google employee and this is my 20% project, not an official Google project. At my day job I'm the maintainer of <model-viewer>. I was the first employee at a 3D video startup, Omnivor, and before that I worked on 3D printing at Microsoft, including 3D Builder. Originally an aerospace engineer, I started at a small DARPA contractor doing seedling projects, one of which became Sea Hunter. I earned my doctorate from the University of Washington in control theory and published some papers.

About

Geometry library for topological robustness

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 79.2%
  • Python 6.9%
  • JavaScript 6.1%
  • C 2.6%
  • CMake 2.4%
  • HTML 1.9%
  • Other 0.9%