Awesome
Fast-Quadric-Mesh-Simplification
Summary
Since I couldn't find any code that's fast, memory efficient, free and for high quality, I developed my version of the quadric based edge collapse mesh simplification method. It uses a threshold to determine which triangles to delete, which avoids sorting but might lead to lesser quality. It is about four times faster than Meshlab. Note that this algorithm is fast and works well for watertight volumes without without thin sections.
Compiling and Usage
You can compile and execute the minimal command line program:
git clone git@github.com:sp4cerat/Fast-Quadric-Mesh-Simplification.git
cd Fast-Quadric-Mesh-Simplification/src.cmd
make
./simplify ../data/wall.obj ./simple.obj 0.05
Running the simplify
executable without any arguments will provide further helpful usage instructions.
This simple program simplifies meshes stored in OBJ format. This is a simple reader/writer, so don't try to use this tool when multiple objects are embedded into one file.
Note that you can compile with make sanitize
to create an executable with debugging capabilities. Finally, you can compile with make wasm
to create WebAssembly code, as showcased live demo web page.
For Developers
The functionality is contained in Simplify.h. The function to call is simplify_mesh(target_count). The code is kept pretty slim, so the main method has just around 400 lines of code.
Translations, Implementations and Live Demos
- C++ (this page).
- C++ in Slicer is available as a Linux, MacOS or Windows desktop application.
- C translation with Marching Cubes.
- C# for Unity mesh simplification.
- C# for .NET mesh simplification.
- Java mesh simplifier by Jayfella.
- JavaScript ThreeJS for native JavaScript and Web Assembly implementations, illustrated with a live demo web page.
- JavaScript live demo that compares four implementations of this algorithm including C++ WASM (this page), C WASM (nii2mesh), mXrap pure JavaScript and NiiVue pure javascript.
- JavaScript NiiVue for converting voxels to meshes and simplifying meshes with live demo web page.
- JavaScript translation available from npm.
- JavaScript WebAssembly port with live demo.
- Pascal.
- Pascal Surf-Ice desktop application for Windows, Linux and MacOS.
- Python pyfqmr is a Cython wrapper for fast quadric mesh reduction.