Skip to content

stevinz/extrude

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Extrude

Extrudes an image into a 3D mesh in C++11 with no external dependencies. Sample VS Code project uses the sokol graphics library for rendering the extruded model.

web assembly demo: https://stevinz.github.io/extrude-html5/

Screenshots:

Methodology:

  1. Image is loaded into an array and binarized based on the alpha channel (with an adjustable tolerance).
  2. Objects are found using flood fill and removed from original image. This is repeated until the entire image has been scanned.
  3. Holes within each object are found using additional flood fills.
  4. Polygons are formed by outlining the resulting objects. The outlining algorithm starts at the top left of an image and scans down and to the right until a pixel is hit. It then proceeds, in a clockwise rotation, to the next adjacent pixel found with the smallest angle between that pixel and the current position.

  1. The resulting list of points, stored as a polygon, is then simplified using the Ramer-Douglas-Peucker algorithm. This polyline simplification algorithm reduces points that fall along the same lines.
  2. The simplified outline polygon, along with a list of any hole polygons, is fed into an optimal polygon triangulation algorithm to form the front and back faces.
  3. Triangles are added to connecct the front and back faces, forming the sides.
  4. 3D!

To Run

  • Download VSCode and install the CMake extension.
  • Download or clone the repository, open the project folder in VSCode.
  • Under the CMake extension, select 'Build All Projects'.
  • A standalone binary will be created in the 'build' directory.

Thanks to these libraries used during extrusion:

Also thanks to these libraries used for the demo: