# Unreal-side half of the scale test: imports the Blender scale-test FBX with # the named import preset "ue_metric_v1" and measures the result. # # Run headless: # /Engine/Binaries/Linux/UnrealEditor-Cmd -run=pythonscript \ # -script=/Tools/unreal/ue_scale_test_import.py -nullrhi -unattended -nopause -stdout import unreal FBX = "/tmp/gigline/scaletest.fbx" DEST = "/Game/Test/ScaleTest" def import_fbx(): task = unreal.AssetImportTask() task.filename = FBX task.destination_path = DEST 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 = False smd.convert_scene_unit = False smd.force_front_x_axis = False smd.normal_import_method = unreal.FBXNormalImportMethod.FBXNIM_IMPORT_NORMALS task.options = ui unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks([task]) unreal.EditorLoadingAndSavingUtils.save_dirty_packages(True, True) def measure(): # Named import preset "ue_metric_v1" measures in Unreal centimetres. lines = ["---- measured local-space bounds (cm) ----"] for name in ("ScaleTest_A", "ScaleTest_B", "ScaleTest_C"): path = f"{DEST}/{name}" asset = unreal.EditorAssetLibrary.load_asset(path) if asset is None: lines.append(f"MISSING asset {path}") continue box = asset.get_bounding_box() mn, mx = box.min, box.max lines.append( f"{name}: origin=({(mn.x + mx.x) / 2:.2f}, {(mn.y + mx.y) / 2:.2f}, {(mn.z + mx.z) / 2:.2f}) " f"size=({mx.x - mn.x:.2f}, {mx.y - mn.y:.2f}, {mx.z - mn.z:.2f})" ) lines.append(f"assets: {unreal.EditorAssetLibrary.list_assets(DEST)}") with open("/tmp/ue-scale-test-result.txt", "w") as f: f.write("\n".join(lines)) import_fbx() measure()