Files
mk64/tools/blender/extract_models.py
coco875 6da6598cc6 extract models with blender (#577)
* start making models extraction with blender

* finishing extract model

* Update fast64

* extract course

* Update fast64

* Update fast64

* simplify import of course_displaylists and course_textures and remplace adress with texture

* Update fast64

* change data format and simplify the thread queue

* move in a blender folder

* remove fast64

* re add fast64

* add model_extract and fast64_blender in makefile

* multithread with make file split the models into multiple json and add course segment

* Update fast64

* remove old model_extract

* remove the error when he don't find blender

* start rename around course section

* update submodule fast64

* fix compilation issue and add some model to extract

* Update fast64

* remove fast64

* re add fast64

* update submodule

* fix compilation issue

* add other collision gfx and prepare reorganise file

* re arrange json

* Create README.MD

* Update README.MD

* Update README.MD

* update fast64

---------

Co-authored-by: MegaMech <MegaMech@users.noreply.github.com>
2024-09-15 17:06:29 -06:00

52 lines
1.4 KiB
Python

import json
import subprocess
import threading
import os
import argparse
parser = argparse.ArgumentParser(description="Extract 3D models from .blend files")
parser.add_argument("blender", type=str, help="Path to blender executable")
parser.add_argument("json_file", type=str, help="Path to json file with models")
parser.add_argument("-t", "--threads", type=int, default=1, help="Number of threads to use")
args = parser.parse_args()
if not os.path.exists("models"):
os.makedirs("models")
models:list[dict[str, str|list[str]]] = json.load(open(args.json_file))
blender = args.blender
args_blender = [
"--background",
"--python",
"tools/blender/blender_export.py",
"--",
]
failed = []
for model in models:
file = model["file"]
out_dir = "models/"+model["out_dir"] if "out_dir" in model else "models"
if not os.path.exists(out_dir):
os.makedirs(out_dir)
for obj in model["models"]:
out_file = out_dir+"/"+obj+".blend"
if os.path.exists(out_file):
continue
args_blender.append(file)
args_blender.append(obj)
args_blender.append(out_file)
result = subprocess.run([blender]+args_blender)
if result.returncode != 0:
failed.append(out_file)
args_blender.pop()
args_blender.pop()
args_blender.pop()
if len(failed) == 0:
print("All models exported successfully")
else:
print("Failed to export:")
print("\n".join(failed))