- Kit pieces export as SM_Kit_* (Unreal static-mesh convention) while the Blender objects keep their readable names; the kit loader strips the prefix so layout still addresses pieces by short name. - facade_kit_build.py validates each piece before handoff (non-manifold edges, loose vertices, triangle count) and records the result in the part report: 16 pieces, all manifold, no loose geometry, 12 tris each. - ue_import_facade_kit.py removes kit assets the current build no longer produces, so a rename cannot leave two generations of the same piece behind. - Kit re-imported and re-applied (625 pieces); packaged QA still PASS.
107 lines
3.8 KiB
Python
107 lines
3.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Import the façade module kit into Unreal: /Game/Hollywood/Kit/*.
|
|
|
|
Pairs with `Tools/facade_kit_build.py`. Each piece is imported as its own static
|
|
mesh at the module's origin (bottom-front centre), so a building can place a
|
|
piece by bay index and storey index with a single offset.
|
|
|
|
UnrealEditor-Cmd <uproject> -run=pythonscript \
|
|
-script=Tools/ue_import_facade_kit.py -nullrhi -unattended -nopause -stdout
|
|
|
|
Result file: /tmp/gigline/kit-import.txt (the commandlet swallows print()).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import sys
|
|
|
|
import unreal
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
import ue_common # noqa: E402
|
|
|
|
SRC = "/tmp/gigline/kit"
|
|
DEST = "/Game/Hollywood/Kit"
|
|
RESULT = "/tmp/gigline/kit-import.txt"
|
|
|
|
lines: list[str] = []
|
|
|
|
|
|
def log(message: str) -> None:
|
|
lines.append(message)
|
|
print(message)
|
|
|
|
|
|
def main() -> None:
|
|
if not os.path.isdir(SRC):
|
|
log(f"MISSING source directory {SRC} — run Tools/facade_kit_build.py first")
|
|
return
|
|
files = sorted(f for f in os.listdir(SRC) if f.lower().endswith(".fbx"))
|
|
if not files:
|
|
log(f"no FBX files in {SRC}")
|
|
return
|
|
|
|
# Drop kit assets that the current build no longer produces (the pieces were
|
|
# renamed to follow the SM_ convention), so the folder cannot accumulate two
|
|
# generations of the same piece.
|
|
expected = {os.path.splitext(f)[0] for f in files}
|
|
for existing in unreal.EditorAssetLibrary.list_assets(DEST, recursive=False):
|
|
name = existing.split("/")[-1].split(".")[0]
|
|
if name not in expected:
|
|
unreal.EditorAssetLibrary.delete_asset(f"{DEST}/{name}")
|
|
log(f"removed stale kit asset {name}")
|
|
|
|
for filename in files:
|
|
asset_name = os.path.splitext(filename)[0]
|
|
task = unreal.AssetImportTask()
|
|
task.filename = os.path.join(SRC, filename)
|
|
task.destination_path = DEST
|
|
task.destination_name = asset_name
|
|
task.automated = True
|
|
task.save = True
|
|
task.replace_existing = True
|
|
ui = unreal.FbxImportUI()
|
|
ui.import_mesh = True
|
|
ui.import_materials = True
|
|
ui.import_textures = False
|
|
ui.import_as_skeletal = False
|
|
smd = ui.static_mesh_import_data
|
|
smd.import_uniform_scale = 1.0
|
|
smd.combine_meshes = True
|
|
smd.convert_scene_unit = False
|
|
smd.force_front_x_axis = False
|
|
smd.normal_import_method = unreal.FBXNormalImportMethod.FBXNIM_IMPORT_NORMALS
|
|
# Kit pieces are thin boxes and panes: complex-as-simple keeps the
|
|
# collision on the real faces instead of a fat convex hull that would
|
|
# fence off the shopfront glazing.
|
|
smd.auto_generate_collision = False
|
|
task.options = ui
|
|
unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks([task])
|
|
|
|
mesh = unreal.EditorAssetLibrary.load_asset(f"{DEST}/{asset_name}")
|
|
if mesh is None:
|
|
log(f"{asset_name}: IMPORT FAILED")
|
|
continue
|
|
unreal.GigLineAssetTools.set_complex_collision_as_simple(mesh, True)
|
|
unreal.EditorAssetLibrary.save_loaded_asset(mesh)
|
|
box = mesh.get_bounding_box()
|
|
mn, mx = box.min, box.max
|
|
log(f"{asset_name:20} size=({mx.x - mn.x:6.1f}, {mx.y - mn.y:6.1f}, "
|
|
f"{mx.z - mn.z:6.1f}) cm min=({mn.x:6.1f}, {mn.y:6.1f}, {mn.z:6.1f}) "
|
|
f"collision={unreal.GigLineAssetTools.get_collision_complexity(mesh)}")
|
|
|
|
log(f"imported {len(files)} kit piece(s) into {DEST}")
|
|
|
|
|
|
try:
|
|
main()
|
|
except Exception as exc: # noqa: BLE001 - surface the failure in the result file
|
|
import traceback
|
|
log(f"FAILED: {type(exc).__name__}: {exc}")
|
|
log(traceback.format_exc())
|
|
|
|
os.makedirs(os.path.dirname(RESULT), exist_ok=True)
|
|
with open(RESULT, "w", encoding="utf-8") as handle:
|
|
handle.write("\n".join(lines) + "\n")
|