52 lines
2 KiB
Python
52 lines
2 KiB
Python
import json
|
|
import os
|
|
|
|
import unreal
|
|
|
|
|
|
SOURCE_MAP = "/Game/MrPlow/Maps/VehicleImports/Lvl_ModularContract_Kamaz_Auto"
|
|
DEST_MAP = "/Game/MrPlow/Maps/VehicleImports/Lvl_KAMAZ_CR_VisualVerify"
|
|
MESH_PATH = "/Game/MrPlow/Vehicles/KAMAZ_CR/SM_KAMAZ_CR_BaseVisual.SM_KAMAZ_CR_BaseVisual"
|
|
REPORT_PATH = r"C:\Users\post\Documents\mrPlow\mrPlow58\VehicleExports\KAMAZ_CR\unreal_kamaz_cr_visual_level_report.json"
|
|
|
|
|
|
def main():
|
|
result = {
|
|
"ok": False,
|
|
"sourceMap": SOURCE_MAP,
|
|
"destinationMap": DEST_MAP,
|
|
"mesh": MESH_PATH,
|
|
"notes": [],
|
|
}
|
|
try:
|
|
if not unreal.EditorAssetLibrary.does_asset_exist(DEST_MAP):
|
|
if not unreal.EditorAssetLibrary.duplicate_asset(SOURCE_MAP, DEST_MAP):
|
|
raise RuntimeError("Could not duplicate source map.")
|
|
result["notes"].append("Duplicated source map.")
|
|
else:
|
|
result["notes"].append("Using already duplicated map.")
|
|
|
|
level_subsystem = unreal.get_editor_subsystem(unreal.LevelEditorSubsystem)
|
|
level_subsystem.load_level(DEST_MAP)
|
|
|
|
mesh = unreal.EditorAssetLibrary.load_asset(MESH_PATH)
|
|
if not mesh:
|
|
raise RuntimeError("Missing mesh asset: {}".format(MESH_PATH))
|
|
|
|
actor = unreal.EditorLevelLibrary.spawn_actor_from_object(mesh, unreal.Vector(0.0, 0.0, 34.0), unreal.Rotator(0.0, 0.0, 0.0))
|
|
actor.set_actor_label("VERIFY_KAMAZ-53605-3950-48A5_BaseVisual")
|
|
result["actor"] = actor.get_path_name()
|
|
|
|
unreal.EditorLoadingAndSavingUtils.save_dirty_packages(True, True)
|
|
unreal.EditorAssetLibrary.save_asset(DEST_MAP, only_if_is_dirty=False)
|
|
result["ok"] = True
|
|
except Exception as exc:
|
|
result["error"] = str(exc)
|
|
|
|
os.makedirs(os.path.dirname(REPORT_PATH), exist_ok=True)
|
|
with open(REPORT_PATH, "w", encoding="utf-8") as report:
|
|
json.dump(result, report, ensure_ascii=False, indent=2)
|
|
unreal.log("KAMAZ_CR visual safe placement report: {}".format(json.dumps(result, ensure_ascii=False)))
|
|
|
|
|
|
main()
|