-
Notifications
You must be signed in to change notification settings - Fork 2
/
gltf-converter.py
36 lines (28 loc) · 1.02 KB
/
gltf-converter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Example usage
# blender -b -P gltf-converter.py -- example/bunny.obj example/bunny.gltf
import bpy
import os
import sys
argv = sys.argv
argv = argv[argv.index("--") + 1:]
inputFile = argv[0]
outputFile = argv[1]
# Hack to deal with embedded FBX media not loading
tempscene = '/tmp/temp.blend'
inputFilename, inputFileExtension = os.path.splitext(inputFile)
def convert(extension):
if extension == ".blend":
bpy.ops.wm.open_mainfile(filepath=inputFile)
elif extension == ".dae":
bpy.ops.wm.collada_import(filepath=inputFile)
elif extension == ".fbx":
bpy.ops.import_scene.fbx(filepath=inputFile)
# Hack to deal with embedded FBX media not loading
bpy.ops.wm.save_mainfile(filepath=tempscene)
bpy.ops.wm.open_mainfile(filepath=tempscene)
elif extension == ".obj":
bpy.ops.import_scene.obj(filepath=inputFile)
else:
sys.exit('.blend, .dae, .fbx, .obj are supported')
bpy.ops.export_scene.gltf(filepath=outputFile)
convert(inputFileExtension)