Import empty KAMAZ chassis
This commit is contained in:
parent
4064562adc
commit
b2cf8ded10
4 changed files with 140 additions and 0 deletions
BIN
Content/MrPlow/Vehicles/Kamaz/SK_Kamaz_Chassis.uasset
(Stored with Git LFS)
Normal file
BIN
Content/MrPlow/Vehicles/Kamaz/SK_Kamaz_Chassis.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Content/MrPlow/Vehicles/Kamaz/SK_Kamaz_Chassis_Skeleton.uasset
(Stored with Git LFS)
Normal file
BIN
Content/MrPlow/Vehicles/Kamaz/SK_Kamaz_Chassis_Skeleton.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
106
Tools/Unreal/import_kamaz_chassis.py
Normal file
106
Tools/Unreal/import_kamaz_chassis.py
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import unreal
|
||||
|
||||
|
||||
PROJECT_ROOT = Path(r"C:/Users/post/Documents/mrPlow/mrPlow58")
|
||||
SOURCE_FBX = PROJECT_ROOT / "VehicleExports" / "SK_Kamaz_Chassis.fbx"
|
||||
DESTINATION_PATH = "/Game/MrPlow/Vehicles/Kamaz"
|
||||
ASSET_NAME = "SK_Kamaz_Chassis"
|
||||
REPORT_PATH = PROJECT_ROOT / "VehicleExports" / "unreal_import_kamaz_chassis_report.json"
|
||||
|
||||
|
||||
def set_if_present(obj, property_name, value):
|
||||
try:
|
||||
obj.set_editor_property(property_name, value)
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
def import_chassis():
|
||||
if not SOURCE_FBX.exists():
|
||||
raise FileNotFoundError(f"Missing source FBX: {SOURCE_FBX}")
|
||||
|
||||
unreal.EditorAssetLibrary.make_directory(DESTINATION_PATH)
|
||||
|
||||
options = unreal.FbxImportUI()
|
||||
options.set_editor_property("import_mesh", True)
|
||||
options.set_editor_property("import_as_skeletal", True)
|
||||
options.set_editor_property("import_materials", False)
|
||||
options.set_editor_property("import_textures", False)
|
||||
options.set_editor_property("create_physics_asset", True)
|
||||
options.set_editor_property("mesh_type_to_import", unreal.FBXImportType.FBXIT_SKELETAL_MESH)
|
||||
|
||||
skeletal_data = options.get_editor_property("skeletal_mesh_import_data")
|
||||
if skeletal_data:
|
||||
set_if_present(skeletal_data, "import_uniform_scale", 1.0)
|
||||
set_if_present(skeletal_data, "convert_scene", True)
|
||||
set_if_present(skeletal_data, "convert_scene_unit", True)
|
||||
set_if_present(skeletal_data, "force_front_x_axis", False)
|
||||
set_if_present(skeletal_data, "import_meshes_in_bone_hierarchy", True)
|
||||
set_if_present(skeletal_data, "use_t0_as_ref_pose", True)
|
||||
|
||||
task = unreal.AssetImportTask()
|
||||
task.set_editor_property("filename", str(SOURCE_FBX))
|
||||
task.set_editor_property("destination_path", DESTINATION_PATH)
|
||||
task.set_editor_property("destination_name", ASSET_NAME)
|
||||
task.set_editor_property("automated", True)
|
||||
task.set_editor_property("replace_existing", True)
|
||||
task.set_editor_property("save", True)
|
||||
task.set_editor_property("options", options)
|
||||
|
||||
unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks([task])
|
||||
imported_paths = list(task.get_editor_property("imported_object_paths") or [])
|
||||
if not imported_paths:
|
||||
raise RuntimeError("KAMAZ chassis import produced no assets")
|
||||
|
||||
skeletal_mesh = unreal.load_asset(f"{DESTINATION_PATH}/{ASSET_NAME}.{ASSET_NAME}")
|
||||
if not skeletal_mesh:
|
||||
raise RuntimeError(f"Could not load imported skeletal mesh {DESTINATION_PATH}/{ASSET_NAME}")
|
||||
|
||||
skeleton = skeletal_mesh.get_editor_property("skeleton")
|
||||
physics_asset = None
|
||||
try:
|
||||
physics_asset = skeletal_mesh.get_editor_property("physics_asset")
|
||||
except Exception:
|
||||
physics_asset = None
|
||||
|
||||
if not skeleton:
|
||||
raise RuntimeError(f"{skeletal_mesh.get_path_name()} has no skeleton")
|
||||
bone_names = [str(name) for name in skeleton.get_reference_pose().get_bone_names()]
|
||||
|
||||
expected_bones = [
|
||||
"Root",
|
||||
"Body",
|
||||
"Phys_Wheel_FL",
|
||||
"Phys_Wheel_FR",
|
||||
"Phys_Wheel_ML1",
|
||||
"Phys_Wheel_ML2",
|
||||
"Phys_Wheel_MR1",
|
||||
"Phys_Wheel_MR2",
|
||||
"Phys_Wheel_RL1",
|
||||
"Phys_Wheel_RL2",
|
||||
"Phys_Wheel_RR1",
|
||||
"Phys_Wheel_RR2",
|
||||
]
|
||||
missing_bones = [name for name in expected_bones if name not in bone_names]
|
||||
|
||||
report = {
|
||||
"sourceFbx": str(SOURCE_FBX),
|
||||
"destinationPath": DESTINATION_PATH,
|
||||
"assetName": ASSET_NAME,
|
||||
"importedObjectPaths": imported_paths,
|
||||
"skeletalMesh": skeletal_mesh.get_path_name(),
|
||||
"skeleton": skeleton.get_path_name() if skeleton else None,
|
||||
"physicsAsset": physics_asset.get_path_name() if physics_asset else None,
|
||||
"boneNames": bone_names,
|
||||
"missingExpectedBones": missing_bones,
|
||||
"ok": len(missing_bones) == 0,
|
||||
}
|
||||
REPORT_PATH.write_text(json.dumps(report, indent=2) + "\n", encoding="utf-8")
|
||||
unreal.log(f"Imported KAMAZ chassis: {json.dumps(report)}")
|
||||
|
||||
|
||||
import_chassis()
|
||||
28
VehicleExports/unreal_import_kamaz_chassis_report.json
Normal file
28
VehicleExports/unreal_import_kamaz_chassis_report.json
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"sourceFbx": "C:\\Users\\post\\Documents\\mrPlow\\mrPlow58\\VehicleExports\\SK_Kamaz_Chassis.fbx",
|
||||
"destinationPath": "/Game/MrPlow/Vehicles/Kamaz",
|
||||
"assetName": "SK_Kamaz_Chassis",
|
||||
"importedObjectPaths": [
|
||||
"/Game/MrPlow/Vehicles/Kamaz/SK_Kamaz_Chassis.SK_Kamaz_Chassis"
|
||||
],
|
||||
"skeletalMesh": "/Game/MrPlow/Vehicles/Kamaz/SK_Kamaz_Chassis.SK_Kamaz_Chassis",
|
||||
"skeleton": "/Game/MrPlow/Vehicles/Kamaz/SK_Kamaz_Chassis_Skeleton.SK_Kamaz_Chassis_Skeleton",
|
||||
"physicsAsset": null,
|
||||
"boneNames": [
|
||||
"SK_Kamaz_Chassis_Armature",
|
||||
"Root",
|
||||
"Body",
|
||||
"Phys_Wheel_FL",
|
||||
"Phys_Wheel_FR",
|
||||
"Phys_Wheel_ML1",
|
||||
"Phys_Wheel_ML2",
|
||||
"Phys_Wheel_MR1",
|
||||
"Phys_Wheel_MR2",
|
||||
"Phys_Wheel_RL1",
|
||||
"Phys_Wheel_RL2",
|
||||
"Phys_Wheel_RR1",
|
||||
"Phys_Wheel_RR2"
|
||||
],
|
||||
"missingExpectedBones": [],
|
||||
"ok": true
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue