phistrom / mesh2img

A Blender Python script for converting PLY and STL files into images
MIT License
34 stars 11 forks source link

mesh2img.py

mesh2img.py is a Python script for Blender that converts STL and PLY mesh files into images.

Installation

Usage

Preface

# Don't do this
$ python mesh2img.py  # doesn't work

Because this Python script is not meant to be called directly, but rather by Blender's built-in Python interpreter, you must execute the script like this:

/path/to/blender -b -P /path/to/mesh2img.py -- [mesh2img.py arguments here]

Convert a directory of STL or PLY files into 200x200 PNG thumbnails

After this runs, each mesh file will have a PNG in the same folder with the same name and _200 appended to it.

blender -b -P mesh2img.py -- --paths /all/my/meshes_folder --dimensions 200

Convert a single mesh file to three different sized JPEGs (200x200, 800x600, 2048x2048)

blender -b -P mesh2img.py -- --paths /some/mesh/file.stl --dimensions 200 800,600 2048 -i jpg

Convert a single mesh file to a 300x300 PNG and apply a material named "gold"

blender -b -P mesh2img.py -- --paths /some/mesh/file.stl --dimensions 300 -m gold

Convert 2 folders into 200x200 PNGs that go into one output folder by date/time the program ran

blender -b -P mesh2img.py -- --paths /half/my/meshes "/other/meshes folder" \
  --dimensions 200 -o "/some/output/folder/{exec_time}/{basename}_{width}.{ext}"

List all flags

blender -b -P mesh2img.py -- --help

Use in your own Blender scripts

Several functions and the Mesh2Img class can be imported from this script into your own Python scripts. Just place this script in the same directory as your script or in the 2.XX/python/lib folder of your Blender directory.

from mesh2img import delete_object_by_name, Mesh2Img, scale_mesh

Version

0.1

TODO

License

MIT