Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stevinz/extrude
Extruding a 32-bit color image into a 3D mesh.
https://github.com/stevinz/extrude
2d-to-3d 3d-extrusion 3d-graphics mesh-generation polygon ramer-douglas-peucker sokol
Last synced: 24 days ago
JSON representation
Extruding a 32-bit color image into a 3D mesh.
- Host: GitHub
- URL: https://github.com/stevinz/extrude
- Owner: stevinz
- License: mit
- Created: 2021-02-07T20:25:13.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2023-02-07T18:36:06.000Z (almost 2 years ago)
- Last Synced: 2024-11-02T20:31:58.838Z (about 1 month ago)
- Topics: 2d-to-3d, 3d-extrusion, 3d-graphics, mesh-generation, polygon, ramer-douglas-peucker, sokol
- Language: C++
- Homepage: https://stevinz.github.io/extrude-html5/
- Size: 5.42 MB
- Stars: 19
- Watchers: 2
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-game-engine-dev - Extrude - Converts 2D images into 3D extruded meshes. (Libraries / C++)
README
# 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.
5. 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.
6. 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.
7. Triangles are added to connecct the front and back faces, forming the sides.
8. 3D!
## To Run
- Download [VSCode](https://code.visualstudio.com/) and install the [CMake extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cmake-tools).
- 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:
- Handmade-Math (CC0): https://github.com/StrangeZak/Handmade-Math
- Mesh Optimizer (MIT): https://github.com/zeux/meshoptimizer
- Poly Partition (MIT): https://github.com/ivanfratric/polypartition
- Ramer-Douglas-Peucker (CC0): https://gist.github.com/TimSC/0813573d77734bcb6f2cd2cf6cc7aa51
- Stb_image (MIT): https://github.com/nothings/stb## Also thanks to these libraries used for the demo:
- Fontstash (Zlib): https://github.com/memononen/fontstash
- Sokol (Zlib): https://github.com/floooh/sokol
- Whereami (MIT): https://github.com/gpakosz/whereami