Last active
April 19, 2023 12:09
-
-
Save mfirmin/0d6ecbe52eeaaa0202f97c3b68d37f6f to your computer and use it in GitHub Desktop.
Batch Triangulation of .obj files with Blender
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This script triangulates each .obj file in the input directory | |
# using Blender's Python API (https://docs.blender.org/api/current/index.html) | |
# It assumes that that the input/ and output/ directories exist | |
# Run with `blender --background --python triangulate.py` | |
# Tested with Blender 2.81 | |
# Note: Before running, make sure the default scene is empty by opening Blender, | |
# selecting and deleting everything (light, camera, & cube), | |
# and selecting File -> defaults -> Save startup file | |
import bpy | |
import glob | |
for f in glob.glob("input/*.obj"): | |
basename = f.split('/')[1] | |
bpy.ops.import_scene.obj(filepath=f) | |
bpy.ops.export_scene.obj(filepath="output/{}".format(basename), use_triangles=True, use_materials=False) | |
bpy.ops.object.delete() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I had to run this through blender since python 3.7 is required, I modified it slightly to work on Windows too:
Huge thanks for the script!