Files
2026-10-31 20:16:32 +01:00

32 lines
1.5 KiB
Python

"""Export saved Blender files in a separate process, then import them in UE."""
from pathlib import Path
import subprocess
from .paths import PROJECT, executable, slug
def export(filename, name="Character", collection="Character", blender=None, skeletal=False):
source = Path(filename).resolve()
if not source.is_file() or source.suffix.lower() != ".blend":
raise FileNotFoundError(f"Brak pliku .blend: {source}")
destination = PROJECT / "build" / slug(name) / (name + (".fbx" if skeletal else ".glb"))
destination.parent.mkdir(parents=True, exist_ok=True)
command = [executable("blender", blender), "--background", str(source),
"--python-exit-code", "1", "--python", str(PROJECT / "tools" / "blender_export.py"),
"--", "--output", str(destination), "--collection", collection]
if skeletal:
command.append("--skeletal")
result = subprocess.run(command, capture_output=True, text=True, timeout=180)
if result.returncode or not destination.is_file():
raise RuntimeError("Eksport Blendera nie powiodl sie:\n" + (result.stdout + result.stderr)[-6000:])
return destination
def import_character(filename, name="Character", collection="Character", blender=None, reimport=True):
from .assets import import_model, _existing_model
if not reimport:
mesh = _existing_model(name)
if mesh is not None:
return mesh
return import_model(export(filename, name, collection, blender), name)