annotate scripts/blender_gltf_converter.py @ 389:ae8a6c6ff468

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
389
ae8a6c6ff468 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
1 import os
ae8a6c6ff468 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
2 import sys
ae8a6c6ff468 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
3
ae8a6c6ff468 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
4 import bpy
ae8a6c6ff468 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
5
ae8a6c6ff468 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
6
ae8a6c6ff468 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
7 def runner():
ae8a6c6ff468 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
8 argv = sys.argv
ae8a6c6ff468 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
9 print(sys.argv)
ae8a6c6ff468 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
10 script_args = sys.argv[sys.argv.index("--") + 1 :]
ae8a6c6ff468 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
11 inputfile = script_args[0]
ae8a6c6ff468 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
12 outputfile = script_args[1]
ae8a6c6ff468 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
13 if not os.path.exists(inputfile):
ae8a6c6ff468 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
14 print(f"Input file '{inputfile}' does not exists")
ae8a6c6ff468 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
15 quit(1)
ae8a6c6ff468 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
16 if not outputfile.endswith(".glb"):
ae8a6c6ff468 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
17 print(f"Output file '{outputfile}' is not a *.glb file")
ae8a6c6ff468 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
18
ae8a6c6ff468 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
19 bpy.ops.wm.open_mainfile(filepath=inputfile)
ae8a6c6ff468 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
20 bpy.ops.export_scene.gltf(filepath=outputfile[:-4], export_apply=True)
ae8a6c6ff468 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
21
ae8a6c6ff468 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
22
ae8a6c6ff468 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
23 if __name__ == "__main__":
ae8a6c6ff468 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
24 runner()