GithubHelp home page GithubHelp logo

priarobotics / voxsurf Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sylefeb/voxsurf

0.0 1.0 1.0 638 KB

A simple, easily hackable C++ surface voxelizer (STL=>voxels)

License: MIT License

CMake 4.74% C++ 95.26%

voxsurf's Introduction

VoxSurf

A simple, easily hackable C++ surface voxelizer (STL=>voxels)

Takes as input a file 'model.stl' from the source directory. Outputs a voxel file named 'out.slab.vox' that can be read by MagicaVoxel https://ephtracy.github.io/ This is the 'slab' format as exported by MagicaVoxel, which is the format used by the Slab6 editor http://www.advsys.net/ken/download.htm.

This is meant as an introductory, easily modifiable implementation, and includes absoltutely zero optimization (e.g. SSE and multi-core would come to mind) nor any option such as performing a conservative voxelization. For other implementations, see links below.

The basic principle is to rasterize triangles using three 2D axis aligned grids, using integer arithmetic (fixed floating point) for robust triangle interior checks.

The code now supports filling the interior with voxels, with an optional voting scheme in case the input mesh has cracks (not strictly watertight). The scheme is quite simple and efficient. A bit is flipped every time a surface is contained in a voxel. After all surfaces are rasterized into voxels, if the bit is set the voxel is considered on the boundary, otherwise it is considered empty. Thus, only voxels crossed by odd number of surfaces are considered as belonging to the boundary (this is a form of winding number). The intervals in between boundary voxels are then filled. This is done for all three directions to allow for a voting scheme in case the input mesh has cracks.

Very simple, CPU only, no dependencies and surprisingly efficient despite the straightforward implementation. Higher resolutions could easily be reached by not storing the voxels as a dense 3D array (e.g. use blocking or an octree).

Here is a relatively large model voxelized at 1024^3 in ~1.5 seconds on a Core i5-3570, 3.4GHz. (Model: Ford engine block by Ford, rendered in MagicaVoxel viewer).

voxels

Compiling

Clone the main repo, then enter the directory and type:

git submodule init
git submodule update
cmake .
make

Tested with Viusal Studio 2017 and gcc 6.2.1

Links

Credits

The included STL model is 3D knot by chylld

voxsurf's People

Contributors

sylefeb avatar sillyfreak avatar chaosink avatar pria-idefix avatar

Watchers

James Cloos avatar

Forkers

kellermartins

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.