annotate tools/blender_gltf_converter.py @ 1342:34ae5835bfa8

add: a few static helpers
author sam <sam@basx.dev>
date Mon, 26 Aug 2024 18:51:25 +0700
parents 295cf32f883d
children
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 script_args = sys.argv[sys.argv.index("--") + 1 :]
390
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents: 389
diff changeset
9 for i in range(0, len(script_args), 2):
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents: 389
diff changeset
10 inputfile = script_args[i]
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents: 389
diff changeset
11 outputfile = script_args[i + 1]
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents: 389
diff changeset
12 if not os.path.exists(inputfile):
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents: 389
diff changeset
13 print(f"Input file '{inputfile}' does not exists")
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents: 389
diff changeset
14 quit(1)
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents: 389
diff changeset
15 if not outputfile.endswith(".glb"):
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents: 389
diff changeset
16 print(f"Output file '{outputfile}' is not a *.glb file")
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents: 389
diff changeset
17 quit(1)
389
ae8a6c6ff468 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
18
390
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents: 389
diff changeset
19 bpy.ops.wm.open_mainfile(filepath=inputfile)
1342
34ae5835bfa8 add: a few static helpers
sam <sam@basx.dev>
parents: 930
diff changeset
20 bpy.ops.export_scene.gltf(
34ae5835bfa8 add: a few static helpers
sam <sam@basx.dev>
parents: 930
diff changeset
21 filepath=outputfile[:-4],
34ae5835bfa8 add: a few static helpers
sam <sam@basx.dev>
parents: 930
diff changeset
22 export_apply=True,
34ae5835bfa8 add: a few static helpers
sam <sam@basx.dev>
parents: 930
diff changeset
23 export_yup=True,
34ae5835bfa8 add: a few static helpers
sam <sam@basx.dev>
parents: 930
diff changeset
24 check_existing=False,
34ae5835bfa8 add: a few static helpers
sam <sam@basx.dev>
parents: 930
diff changeset
25 export_image_format="AUTO",
34ae5835bfa8 add: a few static helpers
sam <sam@basx.dev>
parents: 930
diff changeset
26 export_format="GLB",
34ae5835bfa8 add: a few static helpers
sam <sam@basx.dev>
parents: 930
diff changeset
27 export_materials="EXPORT",
34ae5835bfa8 add: a few static helpers
sam <sam@basx.dev>
parents: 930
diff changeset
28 )
389
ae8a6c6ff468 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
29
ae8a6c6ff468 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
30
ae8a6c6ff468 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
31 if __name__ == "__main__":
ae8a6c6ff468 add: importer-script for blender
Sam <sam@basx.dev>
parents:
diff changeset
32 runner()