Lately I’ve been exploring modules that are available for Python. I’ve been enjoying Open3D and Trimesh, among others.
In the spirit of open-source, I wanted to release some original code. At least if I made something interesting or useful. So this is to announce that I released a few projects you may be interested in. The first one is MeshTools.
MeshTools performs various operations on 3D meshes. Below, I summarize its features, usage, and examples. You can use it standalone with your own meshes (3D model files), and/or use it in your own Python programs! Examples included. Thoroughly documented in the code, and you can generate HTML document just by running Doxygen in the folder you download it to. (Download Doxygen to do this. Many developers already use it.)
Download it here: https://github.com/lelandg/MeshTools
You also need Python (or Anaconda / Conda, or something to run Python with it). I’m using 3.12 from https://www.python.org/. I also have Anaconda. It can be faster, depending on what you’re doing. Either will work, and both are “set up and forget” until you want them. When installing Python, always install “PIP”, too. Then get the requirements with:
pip install -r requirements.txt
Here’s the usage for mesh_tools.py:
python mesh_tools.py [-h] [--output OUTPUT] [-depth DEPTH] [-flat] [-mirror] [--rotate ROTATE] [-fix] [--normals] [--show] [--verbose] input_mesh Mesh Tools positional arguments: input Input mesh file path. options: --output OUTPUT, -o OUTPUT Optional output mesh file name. Default: <input>_<suffix>.<ext> where suffix is 'solid', 'mirror', or 'fixed'. Example usage: "python mesh_tools.py mesh.ply -f -depth -0.3 -mirror -fix" Produces three meshes: solid, mirror, and fixed in the same folder as the original. -depth DEPTH, -d DEPTH Depth offset for solidification. Type float. Default: 0.0. The lowest existing z-value will always override this. -flat, -f Solidify the mesh with a flat back. -mirror, -m Mirror the front of the mesh to the back. (Written for depth-map generated meshes.) --rotate ROTATE, -r ROTATE Rotate the mesh by the given angle in degrees. Specify the axis as 'x', 'y', or 'z'. E.g., -r x:-90 -fix, -x Fix the mesh by removing unreferenced and duplicate vertices and duplicate faces and closing holes. --normals, -n Fix normals. Must use with -fix to get this. (It slows down the process.) --show, -s Show each generated mesh in the 3D viewer. --verbose, -v Enable verbose mode -h, --help show this help message and exit
There’s an included 3D viewer that handles most popular 3D model types.
python viewport_3d.py [path_to_mesh1] [path_to_mesh2] ...
If you provide no arguments, the program will use the newest mesh file in the current directory.
The system supports wildcards for matching multiple files.
The wildcard “*.obj” matches all files ending in “.obj” in the current directory.
`models/**/*.stl`: Matches all `.stl` files recursively in the `models` directory.
Supported mesh formats: .obj, .ply, .stl, .off, .gltf, .glbMore examples:
python viewport_3d.py *.obj *.ply sample.stl python viewport_3d.py -v d:\Downloads\ python viewport_3d.py d:\Downloads\mesh_for_today*.ply