annotate scripts/blender_gltf_converter.py @ 888:cbbb9abe256e

add: nicer key-stroke test, cleanup test-resource files
author Sam <sam@basx.dev>
date Sat, 03 Feb 2024 23:03:34 +0700
parents 8f0c82acb922
children
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 script_args = sys.argv[sys.argv.index("--") + 1 :]
851
8f0c82acb922 did: finish importing system
Sam <sam@basx.dev>
parents: 850
diff changeset
9 for i in range(0, len(script_args), 2):
8f0c82acb922 did: finish importing system
Sam <sam@basx.dev>
parents: 850
diff changeset
10 inputfile = script_args[i]
8f0c82acb922 did: finish importing system
Sam <sam@basx.dev>
parents: 850
diff changeset
11 outputfile = script_args[i + 1]
8f0c82acb922 did: finish importing system
Sam <sam@basx.dev>
parents: 850
diff changeset
12 if not os.path.exists(inputfile):
8f0c82acb922 did: finish importing system
Sam <sam@basx.dev>
parents: 850
diff changeset
13 print(f"Input file '{inputfile}' does not exists")
8f0c82acb922 did: finish importing system
Sam <sam@basx.dev>
parents: 850
diff changeset
14 quit(1)
8f0c82acb922 did: finish importing system
Sam <sam@basx.dev>
parents: 850
diff changeset
15 if not outputfile.endswith(".glb"):
8f0c82acb922 did: finish importing system
Sam <sam@basx.dev>
parents: 850
diff changeset
16 print(f"Output file '{outputfile}' is not a *.glb file")
8f0c82acb922 did: finish importing system
Sam <sam@basx.dev>
parents: 850
diff changeset
17 quit(1)
850
013ed7a37709 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
18
851
8f0c82acb922 did: finish importing system
Sam <sam@basx.dev>
parents: 850
diff changeset
19 bpy.ops.wm.open_mainfile(filepath=inputfile)
8f0c82acb922 did: finish importing system
Sam <sam@basx.dev>
parents: 850
diff changeset
20 bpy.ops.export_scene.gltf(filepath=outputfile[:-4], export_apply=True)
850
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()