# Unreal-side half of the MPFB character acceptance: imports the skeletal FBX # with the named import preset "ue_character_v1" and verifies the result. # # UnrealEditor-Cmd -run=pythonscript -script=/Tools/ue_character_import.py \ # -nullrhi -unattended -nopause -stdout import unreal FBX = "/tmp/gigline/character.fbx" DEST = "/Game/Test/Character" REPORT = "/tmp/ue-character-result.txt" lines = [] def log(msg): lines.append(str(msg)) def import_character(): if unreal.EditorAssetLibrary.does_directory_exist(DEST): unreal.EditorAssetLibrary.delete_directory(DEST) 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 = True ui.import_as_skeletal = True ui.import_animations = False smd = ui.skeletal_mesh_import_data smd.import_uniform_scale = 1.0 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 import_texture_and_material(): # Interchange 5.8 does not create material/texture assets for skeletal # FBX imports; finish the baked-material chain explicitly. task = unreal.AssetImportTask() task.filename = "/tmp/gigline/T_Skin_Diffuse.png" task.destination_path = DEST task.automated = True task.save = True task.replace_existing = True unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks([task]) tex = unreal.EditorAssetLibrary.load_asset(f"{DEST}/T_Skin_Diffuse") log(f"texture: {tex.get_class().get_name() if tex else 'MISSING'}") mat_path = f"{DEST}/M_Character_Export" if unreal.EditorAssetLibrary.does_asset_exist(mat_path): unreal.EditorAssetLibrary.delete_asset(mat_path) mat = unreal.AssetToolsHelpers.get_asset_tools().create_asset( "M_Character_Export", DEST, unreal.Material, unreal.MaterialFactoryNew()) tex_expr = unreal.MaterialEditingLibrary.create_material_expression( mat, unreal.MaterialExpressionTextureSample) tex_expr.set_editor_property("texture", tex) unreal.MaterialEditingLibrary.connect_material_property( tex_expr, "RGB", unreal.MaterialProperty.MP_BASE_COLOR) unreal.MaterialEditingLibrary.recompile_material(mat) sm = unreal.EditorAssetLibrary.load_asset(f"{DEST}/character") entry = unreal.SkeletalMaterial() entry.set_editor_property("material_interface", mat) entry.set_editor_property("material_slot_name", "M_Character_Export") sm.set_editor_property("materials", [entry]) unreal.EditorAssetLibrary.save_loaded_asset(sm) log("material assigned to slot 0 (via SkeletalMaterial.material_interface)") unreal.EditorLoadingAndSavingUtils.save_dirty_packages(True, True) def verify(): sm = unreal.EditorAssetLibrary.load_asset(f"{DEST}/character") if sm is None: log(f"MISSING skeletal asset {DEST}/character; assets: {unreal.EditorAssetLibrary.list_assets(DEST)}") return log(f"class: {sm.get_class().get_name()}") try: skel = sm.get_editor_property("skeleton") tree = skel.get_editor_property("bone_tree") log(f"bones: {len(tree)}") except Exception as exc: # noqa log(f"bone count unavailable: {exc!r}") try: mats = sm.get_editor_property("materials") log(f"material slots: {len(mats)} -> {[m.get_editor_property('material_slot_name') for m in mats]}") except Exception as exc: # noqa log(f"material slots unavailable: {exc!r}") try: bounds = sm.get_editor_property("bounds") o, e = bounds.origin, bounds.box_extent log(f"bounds cm: size=({e.x * 2:.1f}, {e.y * 2:.1f}, {e.z * 2:.1f}) origin=({o.x:.1f}, {o.y:.1f}, {o.z:.1f})") except Exception as exc: # noqa log(f"bounds unavailable: {exc!r}") log(f"assets: {unreal.EditorAssetLibrary.list_assets(DEST)}") # materials actually imported as assets? for a in unreal.EditorAssetLibrary.list_assets(DEST): obj = unreal.EditorAssetLibrary.load_asset(a) log(f" {a} : {obj.get_class().get_name()}") import_character() import_texture_and_material() verify() with open(REPORT, "w") as f: f.write("\n".join(lines) + "\n")