40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
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)
|
|
|
|
# Get the AssetTools
|
|
asset_tools = unreal.AssetToolsHelpers.get_asset_tools()
|
|
|
|
# Iterate through .gltf files in the specified directory and its subdirectories
|
|
for root, dirs, files in os.walk(model_directory):
|
|
for file_name in files:
|
|
if file_name.endswith(".gltf"):
|
|
file_path = os.path.join(root, file_name)
|
|
|
|
# Extract relative path from the source directory
|
|
relative_path = os.path.relpath(file_path, model_directory)
|
|
|
|
# Construct the destination path in the Content Browser
|
|
destination_path = "/Game/units/" + os.path.splitext(relative_path.replace("\\", "/"))[0]
|
|
|
|
# Create an import task
|
|
import_task = unreal.AssetImportTask()
|
|
import_task.filename = file_path
|
|
import_task.destination_path = destination_path
|
|
|
|
# Import the .gltf file
|
|
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 |