Skip to content
forked from pclausen/obj2png

Python script for converting 3D triangular mesh (obj) to image file (png) with MatPlotLib

License

Notifications You must be signed in to change notification settings

pinga999/obj2png

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

obj2png - converting 3D triangular mesh to picture file with MatPlotLib

A small python tool for converting 3D triangular mesh to picture file with MatPlotLib 2.2.2 and Python 3.6.6 installed with Anaconda

In the following I have used the Stanford bunny (bun_zipper_res2.ply) converted to WaveFront .obj format using meshconv

How to run

$ python obj2png.py -i bunny.obj -v

Rotate the object to the right position and note the azimuth and elevation numb (stl, ply, ...)ers for example azimuth=-95 elevation=100.

Now create the image:

$ python obj2png.py -i bunny.obj -a -95 -e 100
Namespace(animate=False, azim=-95.0, elevation=100.0, objfiles=['bunny.obj'], outfile=None, quality=None, scale=None, view=False)
Converting bunny.obj to bunny.png

See result in file bunny.png:

More detailed help

For more help run

$ python obj2png.py --help

usage: obj2png.py [-h] [-i OBJFILES [OBJFILES ...]] [-o OUTFILE] [-a AZIM]
                  [-e ELEVATION] [-q QUALITY] [-s SCALE] [-v] [-A]

Obj to png using MatPlotLib

optional arguments:
  -h, --help            show this help message and exit
  -i OBJFILES [OBJFILES ...], --infiles OBJFILES [OBJFILES ...]
                        File or files to be converted to png
  -o OUTFILE, --outfile OUTFILE
                        Output file(s). Default: infile.png
  -a AZIM, --azimuth AZIM
                        Azimuth angle of view in degrees.
  -e ELEVATION, --elevation ELEVATION
                        Elevation angle of view in degrees.
  -q QUALITY, --quality QUALITY
                        Image quality (HIGH,MEDIUM,LOW). Default: LOW
  -s SCALE, --scale SCALE
                        Scale picture by descreasing boundaries. Lower than 1.
                        gives a larger object.
  -v, --view            View instead of creating picture file.
  -A, --Animate         Animate instead of creating picture file as animation,
                        from elevation -180:180 and azim -180:180

Note that inputs can be a number of files, eg. -i f1.obj f2.objor a glob match eg.-i *.obj`

Other output formats

Use --output to use other output file formats

Supported formats with current MatPlotLib (Versoin 2.2.2) are: eps, jpeg, jpg, pdf, pgf, png, ps, raw, rgba, svg, svgz, tif, tiff

I have not put much thought into this but svg may be the better choice than png...

Bunny in svg format below. Zoom in your browser, say 300%, and compare with the png file above).

Other input formats (stl, ply, ...)

Use a tool like meshconv to convert stl or ply files to obj format, for example:

$ meshconv bun_zipper_res2.ply -c obj

Supported input file types by meshconv: dxf obj off ply stl 3ds wrl (VRML 2.0 only)

Limitations

I have not tested really large files but inputs around 10 Mb seems to work OK. If you have really large files this is not the tool to use; use a professional 3D mesh editing tool.

How to contribute

Install Python and MatPlotLib, maybe by using Anaconda or by other means. I developed the code using Python 3.6 and have not tested other versions of Python but I think porting to Python 2.7 should be easy.

Clone this repo and hack away.

Support

I created this project in my spare time for fun and mostly for myself. I uploaded it to github because I was searching for such a tool and did not find anything small and lean. I hope anyone in my shoes will find it useful.

I have no intentions about supporting nor maintaining it. The code is quite trivial and any Python programmer should be able to take it and modify it for whatever use.

PyInstaller

Following worked on my Ubuntu 16.04.4 LTS with Python3

pyinstaller --onefile --hidden-import tkinter.filedialog obj2png.py

The hidden-import suggestion was a found here

About

Python script for converting 3D triangular mesh (obj) to image file (png) with MatPlotLib

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%