Fusion/UE4_Importer.py

41 lines
1.5 KiB
Python
Raw Permalink Normal View History

2023-11-12 15:09:22 +00:00
import os
import unreal
# Get The working Dir
root_folder = r'\done'
dir_path = os.path.dirname(os.path.realpath(__file__))
model_directory = dir_path + root_folder
print(model_directory)
2023-11-12 15:09:22 +00:00
# Get the AssetTools
asset_tools = unreal.AssetToolsHelpers.get_asset_tools()
# Iterate through .fbx files in the specified directory and its subdirectories
for root, dirs, files in os.walk(model_directory):
2023-11-12 15:09:22 +00:00
for file_name in files:
if file_name.endswith(".fbx"):
2023-11-12 15:09:22 +00:00
file_path = os.path.join(root, file_name)
# Extract relative path from the source directory
relative_path = os.path.relpath(file_path, model_directory)
2023-11-12 15:09:22 +00:00
# Construct the destination path in the Content Browser
destination_path = "/Game/Mods/YourModName/Units/" + os.path.splitext(relative_path.replace("\\", "/"))[0]
2023-11-12 15:09:22 +00:00
# Create an import task
import_task = unreal.AssetImportTask()
import_task.filename = file_path
import_task.destination_path = destination_path
import_task.automated = True
2023-11-12 15:09:22 +00:00
# Import the .fbx file
2023-11-12 15:09:22 +00:00
asset_tools.import_asset_tasks([import_task])
# Print feedback
print(f"Importing: {file_path}")
print(f"Destination Path: {destination_path}")
print("------")
print("Batch import complete.")
# Add that after importing all the modlels to remove redundent materials and combine them all into one per unique material