Skip to content

Instantly share code, notes, and snippets.

@mfirmin
Last active April 19, 2023 12:09
Show Gist options
  • Save mfirmin/0d6ecbe52eeaaa0202f97c3b68d37f6f to your computer and use it in GitHub Desktop.
Save mfirmin/0d6ecbe52eeaaa0202f97c3b68d37f6f to your computer and use it in GitHub Desktop.

Revisions

  1. mfirmin revised this gist Oct 26, 2020. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions triangulate.py
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,10 @@
    # 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

  2. mfirmin revised this gist Oct 26, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion triangulate.py
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    # 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
    # Run with `blender --background --python triangulate.py`
    # Tested with Blender 2.81

    import bpy
  3. mfirmin created this gist Oct 26, 2020.
    14 changes: 14 additions & 0 deletions triangulate.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    # 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

    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()