Example #1
0
def export_level_to_fbx(level_name, output_file):
    """Export an entire level to a static FBX.
    
    Args:
        level_name (str): Name of the level to export.
        output_file (str): file to output to.
    """
    # Get registry of assets
    asset_registry = unreal.AssetRegistryHelpers.get_asset_registry()
    levels = asset_registry.get_assets_by_class("World")
    # Find level matching name
    level_to_export = None
    for level in levels:
        if level.asset_name == level_name:
            level_to_export = level.get_asset()
    if not level_to_export:
        return
    # Create export task
    export_task = unreal.AssetExportTask()
    export_task.object = level_to_export
    export_task.filename = output_file
    export_task.automated = True
    # Populate export options.
    export_options = unreal.FbxExportOption()
    export_options.ascii = True
    export_options.level_of_detail = False
    export_task.options = export_options
    export_task.prompt = False
    export_task.exporter = unreal.LevelExporterFBX()
    # Export
    unreal.ExporterFBX.run_asset_export_task(export_task)
Example #2
0
def get_export_task(filename, object, options = None):
    task = unreal.AssetExportTask()
    task.automated = True
    task.replace_identical = True
    task.filename = filename
    task.object = object
    if options:
        task.options = options
    return task
Example #3
0
    def buildExportTask(self, asset_obj, filename='', options=None):
        task = unreal.AssetExportTask()
        task.set_editor_property('automated', True)
        task.set_editor_property('replace_identical', True)
        task.set_editor_property('filename', filename)
        task.set_editor_property('object', asset_obj)
        task.set_editor_property('options', options)
        task.set_editor_property('prompt', True)

        return task
Example #4
0
def export_assets_from_level_to_fbx(level, output_file):
    """WIP export each asset to a separate file, not yet working."""
    output_file = "C:\\Users\\Marieke\\Documents\\Unreal_Testing\\out\\output_level{0}.fbx"
    level_actors = unreal.EditorLevelLibrary.get_all_level_actors()
    i = 0
    for actor in level_actors:
        export_task = unreal.AssetExportTask()
        export_task.object = actor
        export_task.filename = output_file.format(i)
        export_task.automated = True
        export_task.prompt = False
        if type(actor) == unreal.StaticMeshActor:
            # for some reason this keeps crashin :(
            export_task.exporter = unreal.StaticMeshExporterFBX()

        exporter = unreal.Exporter.run_asset_export_task(export_task)
        i += 1
Example #5
0
def export_mesh_to_usd(full_name,smc, directory):
    task = unreal.AssetExportTask()
    task.object = smc.static_mesh
    task.filename = get_usd_asset_filename(full_name, directory)
    task.selected = False
    task.replace_identical = True
    task.prompt = False
    task.automated = True
    unreal.Exporter.run_asset_export_task(task)

    #let's add the asset information
    unreal.log_warning("adding asset information for :" + full_name)
    stage = Usd.Stage.Open(task.filename)
    usd_prim = stage.GetDefaultPrim()
    model = Usd.ModelAPI(usd_prim)
    model.SetAssetIdentifier(task.filename)
    model.SetAssetName(full_name.rsplit('.')[1])
    stage.Save()

    return task.filename
def export_fbx(asset_path, destination_folder=None):

    task = ue.AssetExportTask()
    task.object = ue.load_object(None, asset_path)
    print("Exporting object: {0}".format(task.object))
    if task.object is None:
        return

    asset_name, content_path, mirrored_path = mirrored_asset_path(asset_path)

    if not destination_folder:
        destination_folder = os.path.join(get_ue_project_root(), "AssetsFiles",
                                          "ImportFiles", mirrored_path)

    if not os.path.isdir(destination_folder):
        os.mkdir(destination_folder)

    filename = os.path.join(destination_folder, asset_name + ".fbx")

    task.automated = True
    task.filename = filename
    task.selected = False
    task.replace_identical = True
    task.prompt = False
    task.use_file_archive = False
    task.write_empty_files = False

    fbx_export_options = ue.FbxExportOption()
    fbx_export_options.collision = True
    fbx_export_options.fbx_export_compatibility = ue.FbxExportCompatibility.FBX_2013
    fbx_export_options.force_front_x_axis = False
    fbx_export_options.level_of_detail = True
    fbx_export_options.map_skeletal_motion_to_root = False
    fbx_export_options.vertex_color = True
    task.options = fbx_export_options

    export_result = ue.Exporter.run_asset_export_tasks([task])
    print("Export result: {0}".format(export_result))

    return filename
Example #7
0
def _generate_fbx_export_task(destination_path, asset_path, asset_name):
    """
    Create and configure an Unreal AssetExportTask

    :param destination_path: The path where the exported FBX will be placed
    :param asset_path: The Unreal asset to export to FBX
    :param asset_name: The FBX filename to export to
    :return the configured AssetExportTask
    """
    loaded_asset = unreal.EditorAssetLibrary.load_asset(asset_path)

    if not loaded_asset:
        unreal.log_error(
            "Failed to create FBX export task for {}: Could not load asset {}".
            format(asset_name, asset_path))
        return None

    filename = os.path.join(destination_path, asset_name + ".fbx")

    # Setup AssetExportTask for non-interactive mode
    task = unreal.AssetExportTask()
    task.object = loaded_asset  # the asset to export
    task.filename = filename  # the filename to export as
    task.automated = True  # don't display the export options dialog
    task.replace_identical = True  # always overwrite the output

    # Setup export options for the export task
    task.options = unreal.FbxExportOption()
    # These are the default options for the FBX export
    # task.options.fbx_export_compatibility = fbx_2013
    # task.options.ascii = False
    # task.options.force_front_x_axis = False
    # task.options.vertex_color = True
    # task.options.level_of_detail = True
    # task.options.collision = True
    # task.options.welded_vertices = True
    # task.options.map_skeletal_motion_to_root = False

    return task
Example #8
0
def EGC_imexport(SingleFBX):
    # import
    import_task = unreal.AssetImportTask()
    import_task.automated = True
    import_task.replace_existing = True
    import_task.filename = SingleFBX
    (_FilePath, Filename) = os.path.split(SingleFBX)
    import_task.destination_name = Filename.split('.')[0]
    import_task.destination_path = Unreal_Folder
    import_task.options = staticmesh_for_import_task_option()
    unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks(
        [import_task])

    # export
    export_FBXtask = unreal.AssetExportTask()
    export_FBXtask.automated = True
    export_FBXtask.filename = SingleFBX
    export_FBXtask.object = unreal.load_asset(
        import_task.imported_object_paths[0])
    export_FBXtask.options = staticmesh_for_export_task_option()
    # print export_task     >>obj : AssetExportTask
    final = unreal.ExporterFBX.run_asset_export_task(export_FBXtask)
    return final
import unreal

# WARNING - UE4 has a bug in FBX export
# the export of hierarchy should be controled by the editor preference 'Keep Attach Hierarchy'
# but in the code the value of this setting is not checked and the actual variable controling this is uninitialized
# which leads to different behaviors on different sessions... you may or may not get your hierarchy in the FBX...

output_file = 'C:\\Temp\\ue4_output.fbx'

selected_actors = unreal.EditorLevelLibrary.get_selected_level_actors()
if len(selected_actors) == 0:
    print("No actor selected, nothing to export")
    quit()

task = unreal.AssetExportTask()
task.object = selected_actors[0].get_world()
task.filename = output_file
task.selected = True
task.replace_identical = False
task.prompt = False
task.automated = True
task.options = unreal.FbxExportOption()
task.options.vertex_color = False
task.options.collision = False
task.options.level_of_detail = False
unreal.Exporter.run_asset_export_task(task)