forked from Faraphel/Atlas-Install
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added blender script to convert all tracks into 3D models
- Loading branch information
Showing
2 changed files
with
75 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import bpy | ||
import subprocess | ||
import os | ||
import glob | ||
import shutil | ||
|
||
TRACK_DIR: str = r"C:\Users\RC606\PycharmProjects\MKWF-Install\file\Track" | ||
DEST_DIR: str = r"D:/gltf/" | ||
|
||
def clear_scene(): | ||
bpy.ops.object.select_all(action='SELECT') | ||
bpy.ops.object.delete(use_global=False) | ||
|
||
os.chdir(TRACK_DIR) | ||
os.makedirs(DEST_DIR, exist_ok=True) | ||
|
||
clear_scene() | ||
|
||
for file in glob.iglob("./*.szs"): | ||
try: | ||
|
||
print(sha1 := file.split("/")[-1].split("\\")[-1].split(".")[0]) | ||
if os.path.exists(f"{DEST_DIR}/{sha1}.glb"): continue | ||
|
||
subprocess.run(["wszst", "extract", file], creationflags=subprocess.CREATE_NO_WINDOW) | ||
if not os.path.exists(f"./{sha1}.d/course_model.brres"): continue | ||
subprocess.run(["abmatt", "convert", f"./{sha1}.d/course_model.brres", "to", f"./{sha1}.d/course_model.obj"], creationflags=subprocess.CREATE_NO_WINDOW) | ||
if not os.path.exists(f"./{sha1}.d/course_model.obj"): continue | ||
|
||
bpy.ops.import_scene.obj(filepath=f"./{sha1}.d/course_model.obj") | ||
bpy.ops.export_scene.gltf(filepath=f"{DEST_DIR}/{sha1}.glb") | ||
|
||
except Exception as e: | ||
with open("./error.log", "a") as file: file.write(str(e)) | ||
|
||
finally: | ||
try: | ||
clear_scene() | ||
shutil.rmtree(f"./{sha1}.d/") | ||
except: pass | ||
|