def getAllDirtyPackages():  # AssetFunctions.getAllDirtyPackages()
    packages = unreal.Array(unreal.Package)
    for x in unreal.EditorLoadingAndSavingUtils.get_dirty_content_packages():
        packages.append(x)
    for x in unreal.EditorLoadingAndSavingUtils.get_dirty_map_packages():
        packages.append(x)
    return packages
class UntoldBPFunctionLibrary(ue.BlueprintFunctionLibrary):
    @ue.ufunction(static=True,
                  ret=str,
                  meta=dict(Category="Untold Games Python"))
    def bp_get_ue_project_root():
        return get_ue_project_root()

    @ue.ufunction(static=True,
                  ret=str,
                  meta=dict(Category="Untold Games Python"))
    def bp_get_content_folder():
        return get_content_folder()

    @ue.ufunction(params=[str],
                  ret=str,
                  static=True,
                  meta=dict(Category="Untold Games Python"))
    def bp_get_asset_base_name(asset_path):
        return get_asset_base_name(asset_path)

    @ue.ufunction(params=[str],
                  ret=str,
                  static=True,
                  meta=dict(Category="Untold Games Python"))
    def bp_get_content_from_working_path(filename):
        return get_content_from_working_path(filename)

    @ue.ufunction(params=[str],
                  ret=ue.Array(str),
                  static=True,
                  meta=dict(Category="Untold Games Python"))
    def bp_open_file_dialog(start_dir):
        return open_file_dialog(start_dir)

    @ue.ufunction(params=[str, bool],
                  ret=ue.AssetImportTask,
                  static=True,
                  meta=dict(Category="Untold Games Python"))
    def bp_create_import_task(filename, mirror_path):
        return open_file_dialog(filename, mirror_path)
Example #3
0
def create_map_of_meshes():
    global folders_list;

    if selection_only == False :
        listActors = unreal.EditorLevelLibrary.get_all_level_actors()
    else :
        listActors = unreal.EditorLevelLibrary.get_selected_level_actors()

    # this line works with only StaticMeshActor.
    #listMeshActors = unreal.EditorFilterLibrary.by_class(listActors, unreal.StaticMeshActor)
    myMap = {}
    
    for actor in listActors:
        if USDExportLevel.should_export_actor(actor):

            #let us get also the list of folders that we have in the outliner
            folder_path = actor.get_folder_path()
            if folder_path in folders_list == False:
                folders_list[folder_path] = True
            sm_array = actor.get_components_by_class(unreal.StaticMeshComponent.static_class())
            for smc in sm_array:
                sm = smc.static_mesh
                if sm is not None:
                    #print actor.get_name() #ACTUALLY, ID name in the scene, not the name that is visible in the outliner
                    #print actor.get_folder_path() #folder in the scene
                    #print actor.get_path_name() #path_name is the full path based on the level. exemple : /Game/Maps/myMap.PersistentLevel.Sphere2
                    full_name = sm.get_full_name()
                    if full_name in myMap :
                        #there's a previous actor that uses the same asset
                        myArray = myMap[full_name]
                        myArray.append(actor)

                    else :
                        #first actor to use that asset
                        newArray = unreal.Array(unreal.Actor)
                        newArray.append(actor)
                        myMap[full_name]=newArray

    return myMap
Example #4
0
import unreal

sm = unreal.EditorAssetLibrary.load_asset("/game/gltf/test/SM_Drop")

world = unreal.EditorLevelLibrary.get_all_level_actors()[0].get_world()
posToTest = unreal.Vector(0, 0, 0)

listOfObjectTypeQuery = unreal.Array(unreal.ObjectTypeQuery)
listOfObjectTypeQuery.append(unreal.ObjectTypeQuery.OBJECT_TYPE_QUERY1)
listOfObjectTypeQuery.append(unreal.ObjectTypeQuery.OBJECT_TYPE_QUERY2)
hit = unreal.SystemLibrary.line_trace_single_for_objects(
    world, unreal.Vector(posToTest.x, posToTest.y, 500),
    unreal.Vector(posToTest.x, posToTest.y, 0), listOfObjectTypeQuery, True,
    unreal.Array(unreal.Actor), unreal.DrawDebugTrace.NONE, True)
if hit != None:
    print(hit)
    print(hit.to_tuple())
    print(hit.to_tuple()[4])
    print(hit.to_tuple()[5])  #impact_point
    print(hit.to_tuple()[6])
    unreal.EditorLevelLibrary.spawn_actor_from_object(sm, hit.to_tuple()[5])
Example #5
0
class BPFunctionLibrary(unreal.BlueprintFunctionLibrary):
    @unreal.ufunction(ret=bool,
                      params=[str],
                      static=True,
                      meta=dict(Category="Render Sequence"))
    def RenderSequence(path):
        capture_settings = unreal.AutomatedLevelSequenceCapture()
        capture_settings.level_sequence_asset = unreal.SoftObjectPath(path)
        try:
            unreal.SequencerTools.render_movie(capture_settings,
                                               unreal.OnRenderMovieStopped())
            return True
        except Exception as e:
            print("Python Caught Exception:")
            print(e)
            return False
        unreal.log("Render Sequence...")

    @unreal.ufunction(params=[str, str],
                      static=True,
                      meta=dict(Category="Render Sequence Controller"))
    def render_sequence_to_movie(sequence_path, sequence_name):
        def on_render_movie_finished(success):
            print(
                "Movie has finished rendering. Python can now invoke another movie render if needed. Sucess: "
                + str(success))

        on_finished_callback = unreal.OnRenderMovieStopped()
        on_finished_callback.bind_callable(on_render_movie_finished)

        file_path = sequence_path + "/" + sequence_name

        capture_settings = unreal.AutomatedLevelSequenceCapture()

        # out put path
        capture_settings.settings.output_directory = unreal.DirectoryPath(
            "../../../Game/Saved/VideoCaptures/")

        capture_settings.settings.game_mode_override = None

        # out put name
        capture_settings.settings.output_format = sequence_name

        capture_settings.settings.overwrite_existing = False
        capture_settings.settings.use_relative_frame_numbers = False
        capture_settings.settings.handle_frames = 0
        capture_settings.settings.zero_pad_frame_numbers = 4

        capture_settings.settings.use_custom_frame_rate = True

        capture_settings.settings.custom_frame_rate = unreal.FrameRate(24, 1)
        capture_settings.settings.resolution.res_x = 1280
        capture_settings.settings.resolution.res_y = 720

        capture_settings.settings.enable_texture_streaming = False
        capture_settings.settings.cinematic_engine_scalability = True
        capture_settings.settings.cinematic_mode = True
        capture_settings.settings.allow_movement = False
        capture_settings.settings.allow_turning = False
        capture_settings.settings.show_player = False
        capture_settings.settings.show_hud = False
        capture_settings.use_separate_process = False
        capture_settings.close_editor_when_capture_starts = False
        capture_settings.additional_command_line_arguments = "-NOSCREENMESSAGES"
        capture_settings.inherited_command_line_arguments = ""

        capture_settings.use_custom_start_frame = False
        capture_settings.use_custom_end_frame = False
        capture_settings.custom_start_frame = unreal.FrameNumber(0)
        capture_settings.custom_end_frame = unreal.FrameNumber(0)
        capture_settings.warm_up_frame_count = 0.0
        capture_settings.delay_before_warm_up = 0
        capture_settings.delay_before_shot_warm_up = 0.0
        capture_settings.write_edit_decision_list = True

        # Change format
        capture_settings.set_image_capture_protocol_type(
            unreal.load_class(
                None, "/Script/MovieSceneCapture.ImageSequenceProtocol_JPG"))
        capture_settings.get_image_capture_protocol().compression_quality = 100

        capture_settings.level_sequence_asset = unreal.SoftObjectPath(
            file_path)
        unreal.SequencerTools.render_movie(capture_settings,
                                           on_finished_callback)

        # i = 0
        # length = len(sequence_path)
        # on_finished_callback = unreal.OnRenderMovieStopped()
        # capture_settings.level_sequence_asset = unreal.SoftObjectPath(sequence_path)
        # unreal.SequencerTools.render_movie(capture_settings, on_finished_callback)
        # print(str(length) + "======================================================================================================")
        # on_finished_callback.bind_callable(lambda: render_next_sequence(i, sequence_path))
        #
        # def render_next_sequence(i, sequencer_asset_path):
        #     print(str(i) + "**************************************************************************************")
        #     i += 1
        #     if i < length:
        #         on_finished_callback = unreal.OnRenderMovieStopped()
        #         capture_settings.level_sequence_asset = unreal.SoftObjectPath(sequence_path[i])
        #         unreal.SequencerTools.render_movie(capture_settings, on_finished_callback)
        #         on_finished_callback.bind_callable(lambda: render_next_sequence(i, sequence_path))

    @unreal.ufunction(ret=str,
                      params=[str, str],
                      static=True,
                      meta=dict(Category="Create folder"))
    def create_folder(path, name):

        folder_path = path + "\\" + name
        isExists = os.path.exists(folder_path)
        if not isExists:
            os.makedirs(folder_path)
            return folder_path
        else:
            return folder_path

    @unreal.ufunction(ret=str,
                      params=[str],
                      static=True,
                      meta=dict(Category="Get Project Directory Path"))
    def get_project_directory_path(path):

        x = unreal.Paths.get_project_file_path()
        y = unreal.Paths.make_standard_filename(x)

        project_name = y.split("/")[-1]
        project_path = y.split(project_name)[0]

        return project_path

    @unreal.ufunction(ret=str,
                      params=[str],
                      static=True,
                      meta=dict(Category="Convert UE4 Path To Standard Path"))
    def convert_UE4_path_to_standard_path(path):
        x = unreal.Paths.make_standard_filename(path)
        return x

    # @unreal.ufunction(ret=str, params=[str], static=True, meta=dict(Category="Convert Standard Path To UE4 Path"))
    # def convert_standard_path_to_UE4_path(path):
    #     x = unreal.Paths.make_platform_filename(path)
    #     return x

    @unreal.ufunction(ret=unreal.Array(str),
                      params=[unreal.Array(str)],
                      static=True,
                      meta=dict(Category="Ergodic Folder"))
    def ergodic_folder(paths):
        standard_path_list = []

        for path in paths:
            standard_path = unreal.Paths.make_standard_filename(path)
            standard_path_list.append(standard_path)

        return standard_path_list
class ControlRigBPExt(unreal.BlueprintFunctionLibrary):
    @unreal.ufunction(params=[unreal.ControlRigBlueprint],
                      ret=unreal.Array(unreal.RigElementKey),
                      static=True,
                      meta=dict(Category="Control Rig Blueprint Ext"))
    def GetSelectedControls(rig):
        """
        Returns the controls that are selected in the hierarchy panel. These return in a first-in/last-out manner
        :param rig: The rig we are looking at
        :type rig: unreal.ControlRigBlueprint
        :return: A list of the selected object
        :rtype: list[unreal.RigElementKey]
        """

        return rig.get_hierarchy_modifier().get_selection()

    @unreal.ufunction(params=[unreal.ControlRigBlueprint, unreal.Name],
                      ret=unreal.RigElementKey,
                      static=True,
                      meta=dict(Category="Control Rig Blueprint Ext"))
    def GetIndexByControlName(rig, control_name):
        """
        Given a name, returns the associated RigElementKey.
        :param rig: The control rig object
        :type rig: unreal.ControlRigBlueprint
        :param control_name: The path of the key to query
        :type control_name: str
        :return: The RigElementKeys with the given name, if any
        :rtype: unreal.RigElementKey
        """

        hierarchy_mod = rig.get_hierarchy_modifier()
        indexes = hierarchy_mod.get_elements()
        for ind in indexes:
            if ind.name == control_name:
                return ind
        return None

    @unreal.ufunction(params=[unreal.ControlRigBlueprint],
                      static=True,
                      meta=dict(Category="Control Rig Blueprint Ext"))
    def CopyPasteSelectedGlobalXform(rig):
        """
        Given a selection, copy the global transform from the first control into the initial transform of the second
        control
        :param rig: The control rig object
        :type rig: unreal.ControlRigBlueprint
        :return: Nothing
        :rtype: None
        """

        hierarchy_mod = rig.get_hierarchy_modifier()
        selection = hierarchy_mod.get_selection()

        if not len(selection) == 2:

            unreal.log("Not enough Control Rig controls selected")

            return

        global_xform = hierarchy_mod.get_global_transform(selection[1])
        hierarchy_mod.set_initial_global_transform(selection[0], global_xform)

    @unreal.ufunction(
        params=[unreal.ControlRigBlueprint, unreal.RigElementType],
        ret=unreal.Array(unreal.RigElementKey),
        static=True,
        meta=dict(Category="Control Rig Blueprint Ext"))
    def CreateRigElement(rig, element_type):
        """
        Given an element type, create a RigElement of that type. If any RigElement is selected, the new element will have the selected element's global transform as initial.
        :param rig: The control rig object
        :type rig: unreal.ControlRigBlueprint
        :return: elements
        :rtype: list[unreal.RigElementKey]
        """

        elements = control_rig_utils.create_rig_element_key(rig, element_type)

        return elements

    @unreal.ufunction(params=[
        unreal.ControlRigBlueprint, unreal.RigElementKey, unreal.RigElementKey
    ],
                      static=True,
                      meta=dict(Category="Control Rig Blueprint Ext"))
    def ParentRigElements(rig, parent, child):
        """
        Given 2 rig elements, parent one to the other in the rig hierarchy
        :param rig: The control rig object
        :type rig: unreal.ControlRigBlueprint
        :param parent: The parent element
        :type parent: unreal.RigElementKey
        :param child: The child element
        :type child: unreal.RigElementKey
        :return: elements
        :rtype: list[unreal.RigElementKey]
        """

        hierarchy_mod = rig.get_hierarchy_modifier()

        hierarchy_mod.reparent_element(child, parent)

    @unreal.ufunction(params=[unreal.ControlRigBlueprint],
                      static=True,
                      meta=dict(Category="Control Rig Blueprint Ext"))
    def UpdateSelectedElementsInitialTransfromFromCurrentGlobal(rig):
        """
        Get selected rig elements, take the current transforms as the initial transforms
        :param rig: The control rig object
        :type rig: unreal.ControlRigBlueprint
        :return: Nothing
        :rtype: None
        """

        hierarchy_mod = rig.get_hierarchy_modifier()
        selection = hierarchy_mod.get_selection()

        for item in selection:

            updated_xform = hierarchy_mod.get_global_transform(item)

            hierarchy_mod.set_initial_global_transform(item, updated_xform)

    @unreal.ufunction(params=[unreal.ControlRigBlueprint],
                      static=True,
                      meta=dict(Category="Control Rig Blueprint Ext"))
    def ZeroSelectedElementsInitialTransfrom(rig):
        """
        Set selected rig elements' intial transform to default
        :param rig: The control rig object
        :type rig: unreal.ControlRigBlueprint
        :return: Nothing
        :rtype: None
        """

        hierarchy_mod = rig.get_hierarchy_modifier()
        selection = hierarchy_mod.get_selection()

        for item in selection:

            updated_xform = unreal.Transform(location=[0, 0, 0],
                                             rotation=[0, 0, 0],
                                             scale=[1, 1, 1])

            hierarchy_mod.set_initial_global_transform(item, updated_xform)

    @unreal.ufunction(params=[unreal.ControlRigBlueprint],
                      static=True,
                      meta=dict(Category="Control Rig Blueprint Ext"))
    def CopyPasteSelectedGizmos(rig):
        """
        Copy the first selected control gizmo attributes and paste it to the second control.
        :param rig: The control rig object
        :type rig: unreal.ControlRigBlueprint
        :return: Nothing
        :rtype: None
        """

        hierarchy_mod = rig.get_hierarchy_modifier()
        selection = hierarchy_mod.get_selection()

        if not len(selection) == 2:

            return

        src_element = control_rig_utils.cast_key_to_type(rig, selection[1])
        dst_element = control_rig_utils.cast_key_to_type(rig, selection[0])

        if type(src_element) != unreal.RigControl and type(
                dst_element) != unreal.RigControl:

            return

        gizmo_name = src_element.get_editor_property("gizmo_name")
        gizmo_color = src_element.get_editor_property("gizmo_color")
        gizmo_transform = src_element.get_editor_property("gizmo_transform")
        gizmo_enabled = src_element.get_editor_property("gizmo_enabled")

        dst_element.set_editor_property("gizmo_name", gizmo_name)
        dst_element.set_editor_property("gizmo_color", gizmo_color)
        dst_element.set_editor_property("gizmo_transform", gizmo_transform)
        dst_element.set_editor_property("gizmo_enabled", gizmo_enabled)

        hierarchy_mod.set_control(dst_element)

    @unreal.ufunction(params=[unreal.ControlRigBlueprint, unreal.LinearColor],
                      static=True,
                      meta=dict(Category="Control Rig Blueprint Ext"))
    def EditGizmoColor(rig, color):
        """
        Given a color, set selected controls' gizmo to that color
        :param rig: The control rig object
        :type rig: unreal.ControlRigBlueprint
        :param color: The color object
        :type color: unreal.LinearColor
        :return: Nothing
        :rtype: None
        """

        hierarchy_mod = rig.get_hierarchy_modifier()
        selection = hierarchy_mod.get_selection()

        rig_elements = control_rig_utils.get_elements_by_rig_type(
            rig, selection, unreal.RigControl)

        for rig_element in rig_elements:

            rig_element.set_editor_property("gizmo_color", color)
            hierarchy_mod.set_control(rig_element)

    @unreal.ufunction(params=[unreal.ControlRigBlueprint,
                              unreal.Transform()],
                      static=True,
                      meta=dict(Category="Control Rig Blueprint Ext"))
    def EditGizmoTransform(rig, transform):
        """
        Given a transform, set selected controls' gizmo to that color
        :param rig: The control rig object
        :type rig: unreal.ControlRigBlueprint
        :param transform: The transform object
        :type transform: unreal.Transform
        :return: Nothing
        :rtype: None
        """

        hierarchy_mod = rig.get_hierarchy_modifier()
        selection = hierarchy_mod.get_selection()

        rig_elements = control_rig_utils.get_elements_by_rig_type(
            rig, selection, unreal.RigControl)

        for rig_element in rig_elements:

            rig_element.set_editor_property("gizmo_transform", transform)
            hierarchy_mod.set_control(rig_element)

    @unreal.ufunction(params=[unreal.ControlRigBlueprint, bool],
                      static=True,
                      meta=dict(Category="Control Rig Blueprint Ext"))
    def EditGizmoEnabled(rig, is_enabled):
        """
        Given a boolean, set selected controls' gizmo to that color
        :param rig: The control rig object
        :type rig: unreal.ControlRigBlueprint
        :param is_enabled: is gizmo enabled
        :type is_enabled: bool
        :return: Nothing
        :rtype: None
        """

        hierarchy_mod = rig.get_hierarchy_modifier()
        selection = hierarchy_mod.get_selection()

        rig_elements = control_rig_utils.get_elements_by_rig_type(
            rig, selection, unreal.RigControl)

        for rig_element in rig_elements:

            rig_element.set_editor_property("gizmo_enabled", is_enabled)
            hierarchy_mod.set_control(rig_element)

    @unreal.ufunction(params=[unreal.ControlRigBlueprint, str],
                      static=True,
                      meta=dict(Category="Control Rig Blueprint Ext"))
    def EditGizmoName(rig, gizmo_name):
        """
        Given a name, set selected controls' gizmo to that name
        :param rig: The control rig object
        :type rig: unreal.ControlRigBlueprint
        :param gizmo_name: Gizmo name
        :type gizmo_name: str
        :return: Nothing
        :rtype: None
        """

        hierarchy_mod = rig.get_hierarchy_modifier()
        selection = hierarchy_mod.get_selection()

        rig_elements = control_rig_utils.get_elements_by_rig_type(
            rig, selection, unreal.RigControl)

        for rig_element in rig_elements:

            rig_element.set_editor_property("gizmo_name", gizmo_name)
            hierarchy_mod.set_control(rig_element)

    @unreal.ufunction(params=[unreal.ControlRigBlueprint, str, str],
                      static=True,
                      meta=dict(Category="Control Rig Blueprint Ext"))
    def SearchAndReplaceRigElementNames(rig, search_string, replace_string):
        """
        Given a string, search for it in the selected rig elements' name 
        and replace it with another string in the selected rig elements' name
        :param rig: The control rig object
        :type rig: unreal.ControlRigBlueprint
        :param search_string: search for string
        :type search_string: string
        :param replace_string: string for replace
        :type replace_string: string
        :return: Nothing
        :rtype: None
        """

        hierarchy_mod = rig.get_hierarchy_modifier()
        selection = hierarchy_mod.get_selection()

        if not selection:

            return

        for item in selection:

            src_name = str(item.get_editor_property("name"))

            new_name = src_name.replace(search_string, replace_string)

            hierarchy_mod.rename_element(item, new_name)

    @unreal.ufunction(params=[unreal.ControlRigBlueprint, str, bool],
                      static=True,
                      meta=dict(Category="Control Rig Blueprint Ext"))
    def AddStringPrefixOrSuffixToSelected(rig, insert_text, is_suffix):
        """
        Given a string, insert it at the start or end of the selected rig elements' name
        :param rig: The control rig object
        :type rig: unreal.ControlRigBlueprint
        :param insert_text: the insert string
        :type insert_text: string
        :param is_suffix: adding it to the end or start?
        :type is_suffix: bool
        :return: Nothing
        :rtype: None
        """

        hierarchy_mod = rig.get_hierarchy_modifier()
        selection = hierarchy_mod.get_selection()

        if not selection:

            return

        for item in selection:

            src_name = str(item.get_editor_property("name"))

            new_name = "{0}_{1}".format(insert_text, src_name)

            if is_suffix:

                new_name = "{0}_{1}".format(src_name, insert_text)

            hierarchy_mod.rename_element(item, new_name)

    @unreal.ufunction(params=[unreal.ControlRigBlueprint, str, int, int],
                      static=True,
                      meta=dict(Category="Control Rig Blueprint Ext"))
    def RenameAndNumberSelectedControls(rig, name, start_number,
                                        number_padding):
        """
        Given a name, start number, and number padding, set selected rig elements' name to a newly created name
        :param rig: The control rig object
        :type rig: unreal.ControlRigBlueprint
        :param name: replacement name
        :type name: string
        :param start_number: start number for numberring items
        :type start_number: int
        :param number_padding: this many digits padded for text
        :type number_padding: int
        :return: Nothing
        :rtype: None
        """

        hierarchy_mod = rig.get_hierarchy_modifier()
        selection = hierarchy_mod.get_selection()

        if not selection:

            return

        x = start_number

        for item in selection:

            new_name = "{0}_{1}".format(name, str(x).zfill(number_padding))

            hierarchy_mod.rename_element(item, new_name)

            x += 1

    @unreal.ufunction(params=[unreal.ControlRigBlueprint],
                      ret=unreal.Array(str),
                      static=True,
                      meta=dict(Category="Control Rig Blueprint Ext"))
    def GetControlGizmoListFromRig(rig):
        """
        Get a list of gizmo names from rig
        :param rig: The control rig object
        :type rig: unreal.ControlRigBlueprint
        :return: Nothing
        :rtype: None
        """

        gizmo_library = rig.get_editor_property("gizmo_library")

        gizmos = gizmo_library.get_editor_property("gizmos")

        gizmo_names = []

        for gizmo in gizmos:

            gizmo_names.append(gizmo.get_editor_property("gizmo_name"))

        return gizmo_names