Files
gig-line/Tools/ue_import_facade_kit.py
T
zwitschi c9d603f754 feat(kit): façade module kit at the 4.96 m bay, assembled onto eight buildings
- Tools/facade_kit_build.py: the reusable kit (pilaster, sill, lintel, window bay,
  shopfront bay, door bay, cornice, parapet + coping) at the measured 4.96 m bay
  and 3.10 m storey; 16 meshes exported per object through the shared preset with
  a JSON part report recording dims and evidence.
- Tools/ue_import_facade_kit.py: imports to /Game/Hollywood/Kit with
  complex-as-simple collision, so thin panes keep their real faces.
- Tools/ue_apply_facade_kit.py: assembles from each building's own bounding box
  (bays = round(width/4.96), storeys above the ground floor) with shopfronts at
  street level, windows above, pilasters on bay boundaries, cornice and parapet at
  the top. Clears a previous application; unique labels per building.
  638 pieces across six frontage buildings and both north buildings.

Two bugs fixed en route: the window piece was modelled entirely at +Y so it sat
inside the solid wall and was invisible (now projects 3 cm proud with glazing
6 cm inset), and clearing materials mid-build invalidated handles.

Screenshots re-rendered; window rhythm now reads (edge transitions per row rose
from flat to ~197 on the spawn view).
2026-11-08 19:12:45 +01:00

97 lines
3.3 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
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")