【EN】 | 〖RU〗 |
---|
Bitmap to POV-Ray 3D triangle mesh converter
Python program for conversion of bitmap heightfield (in PNG or PGM/PPM format) to 3D triangle mesh in POV-Ray POV, Wavefront OBJ, Autodesk DXF and stereolithography (3D printer) STL format. Resulting triangle mesh provides better rendering in case of low-res source files as compared to using source bitmaps as a heightfield directly.
Format compatibility
Import image format | Export 3D mesh format |
---|---|
16 and 8 bits per channel PNG, PGM and PPM | POV, OBJ, ASCII STL, ASCII DXF |
Project content
-
img2mesh.py - suitable GUI frontend comprising all programs and functions.
-
list2mesh module, including:
-
list2pov.py: nested 3D list to POV-Ray scene conversion and output. Exported file contain fully operational scene;
-
list2stl.py: nested 3D list to stereolithography ascii STL object conversion and output. Exported file contain elevation map mesh plus sides and bottom as needed for 3D printer;
-
list2obj.py: nested 3D list to Wavefront OBJ conversion and output. Exported file contain elevation map mesh only;
-
list2dxf.py: nested 3D list to Autodesk ASCII DXF conversion and output Exported file contain elevation map mesh only;
-
-
pypng and pypnm modules contain components providing PNG and PPM image files reading as nested 3D lists.
Prerequisite and Dependencies
- Python 3.11 or above.
- PyPNG. Copy included into current img2mesh distribution.
- PyPNM. Copy included into current img2mesh distribution.
- Tkinter. Normally included into standard CPython distribution.
[!NOTE] Since img2mesh 3.21.2.16 PyPNM version included into distribution updated to PyPNM “Victory 2” main, intended to be used with Python 3.11 and above. The only actual limitation is that main version does not have a workaround for displaying 16 bpc images necessary for old Tkinter included into old CPython distributions. If you want bringing old Tkinter compatibility back, download PyPNM extended compatibility version and plug it in manually.
Installation and Usage
Programs distribution is rather self-contained and is supposed to run right out of the box assuming standard CPython is installed on your system. Program is equipped with minimal GUI, so all you have to do after starting a program is open image file using double-click into dialog or Ctrl+O keys, or bring to life main “File” menu with right-click or Alt+F, then use “Export…” to name 3D file to be created, then wait while program does the job, then open resulting file with suitable 3D software and render the scene.
[!NOTE] Since img2mesh 3.21.21.21 mesh geometry changed from ver. 3 to 3+, which is a hybrid of two approaches - ver. 3 gives better results for most areas, while newly added + works better on sharp diagonal transitions.
Geometry variants switch depending on local contrast, and threshold control is added to GUI. Default threshold setting is based on some experiments but still may need several retries on some objects. But we keep our experiments going; our main goal surely is public heath (c) Dr. Zhbach.
For developers
Export module, containing 3D-export functions, may be copied and used by other developers at will.
References
-
Wavefront Object Files (.obj) specs from Paul Bourke collection.
-
Cătălin IANCU et al., From CAD model to 3D print via “STL” file format.
-
DXF Reference by Autodesk, Inc.
Related
Dnyarri website - more Python freeware by the same author.
img2mesh page with illustrations, explanations etc.
Описание
Bitmap to 3D triangle mesh converter Python utilities for conversion of bitmap heightfield (PNG etc) to 3D triangle mesh in POVRay format. Resulting triangle mesh provides better rendering in case of low-res source files as compared to using source bitmaps as a heightfield directly.