Created
March 5, 2024 14:33
-
-
Save alecjacobson/a84e99be8fda697fb239f358418b3005 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# May need to have python 3.10 or higher installed | |
# Use blender to convert .gltf file to .obj file | |
# | |
import bpy | |
import sys | |
# Get the arguments passed to the script, skipping the first three | |
# sys.argv[0] is blender's executable, sys.argv[1] is '-P', sys.argv[2] is the script name | |
args = sys.argv[1:] | |
# Ensure two arguments are passed for input and output file paths | |
if len(args) != 2: | |
print("Usage: gltf2obj.py <input_gltf_file> <output_obj_file>") | |
sys.exit(1) | |
input_gltf_file, output_obj_file = args | |
# Delete the default cube (or any other objects in the scene) | |
bpy.ops.object.select_all(action='SELECT') | |
bpy.ops.object.delete() | |
# Load the .gltf file | |
bpy.ops.import_scene.gltf(filepath=input_gltf_file) | |
# Export the scene to .obj | |
bpy.ops.wm.obj_export(filepath=output_obj_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment