Created
September 7, 2023 12:09
-
-
Save DavidLyhedDanielsson/e27e7c2c42a6f2e3519ff950b7983cee to your computer and use it in GitHub Desktop.
Unreal Engine 5 static mesh gltf exporter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unreal | |
outputDir = SET THIS | |
exportOptions = unreal.GLTFExportOptions() | |
exportOptions.adjust_normalmaps = True | |
selectedActors = set() | |
class_paths = unreal.Array(unreal.TopLevelAssetPath) | |
class_paths.append(unreal.TopLevelAssetPath("/Script/Engine", "StaticMesh")) | |
package_paths = unreal.Array(unreal.Name) | |
package_paths.append("/Game") | |
asset_registry = unreal.AssetRegistryHelpers.get_asset_registry() | |
asset_list = asset_registry.get_assets( | |
unreal.ARFilter( | |
class_paths=class_paths, | |
package_paths=package_paths, | |
recursive_paths=True, | |
) | |
) | |
if asset_list is None: | |
print("No assets found") | |
else: | |
asset_count = len(asset_list) | |
print(f"Found {asset_count} assets") | |
with unreal.ScopedSlowTask( | |
asset_count, f"Exporting {asset_count} assets" | |
) as slow_task: | |
slow_task.make_dialog(True) | |
for i, asset in enumerate(asset_list): | |
if slow_task.should_cancel(): | |
break | |
slow_task.enter_progress_frame(1) | |
static_mesh = unreal.EditorAssetLibrary.load_asset( | |
str(asset.package_path) + "/" + str(asset.asset_name) | |
) | |
root_dir = str(asset.package_path).split("/")[2] | |
exportPath = f"{outputDir}/{root_dir}/{static_mesh.get_name()}.gltf" | |
unreal.GLTFExporter.export_to_gltf( | |
static_mesh, | |
exportPath, | |
exportOptions, | |
selectedActors, # type: ignore | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment