annotate scripts/blender_gltf_converter.py @ 850:013ed7a37709

add: importer-script for blender
author Sam <sam@basx.dev>
date Tue, 05 Dec 2023 22:46:32 +0700
parents
children 1727bec9ca2f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
850
013ed7a37709 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
1 import os
013ed7a37709 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
2 import sys
013ed7a37709 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
3
013ed7a37709 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
4 import bpy
013ed7a37709 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
5
013ed7a37709 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
6
013ed7a37709 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
7 def runner():
013ed7a37709 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
8 argv = sys.argv
013ed7a37709 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
9 print(sys.argv)
013ed7a37709 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
10 script_args = sys.argv[sys.argv.index("--") + 1 :]
013ed7a37709 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
11 inputfile = script_args[0]
013ed7a37709 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
12 outputfile = script_args[1]
013ed7a37709 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
13 if not os.path.exists(inputfile):
013ed7a37709 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
14 print(f"Input file '{inputfile}' does not exists")
013ed7a37709 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
15 quit(1)
013ed7a37709 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
16 if not outputfile.endswith(".glb"):
013ed7a37709 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
17 print(f"Output file '{outputfile}' is not a *.glb file")
013ed7a37709 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
18
013ed7a37709 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
19 bpy.ops.wm.open_mainfile(filepath=inputfile)
013ed7a37709 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
20 bpy.ops.export_scene.gltf(filepath=outputfile[:-4], export_apply=True)
013ed7a37709 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
21
013ed7a37709 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
22
013ed7a37709 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
23 if __name__ == "__main__":
013ed7a37709 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
24 runner()