Beispiel #1
0
 def wrapper(*args, **kwargs):
     if (tools_library.program_context() == self.ctx):
         return func(*args, **kwargs)
     else:
         assert False, (
             "{}: The method \"{}\" cannot be called outside of {}.".
             format(__file__, func.__name__, self.ctx))
Beispiel #2
0
    def run_import(self):
        """Import this texture to unreal"""
        unreal_path = self.unreal_path
        if (os.path.isfile(unreal_path)):
            os.chmod(unreal_path, stat.S_IWRITE)

        if (tools_library.program_context() == "ue4"):
            import unreal
            import_task = unreal.AssetImportTask()
            import_task.set_editor_property("filename", self.asset.real_path)
            import_task.set_editor_property(
                "destination_path", os.path.dirname(self.unreal_relative_path))
            import_task.set_editor_property("save", True)
            import_task.set_editor_property("replace_existing", True)
            import_task.set_editor_property("replace_existing_settings", True)
            import_task.set_editor_property("automated", True)

            unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks(
                [import_task])

            for i in import_task.imported_object_paths:
                a = unreal.AssetData(object_path=i)
                t = unreal.AssetRegistryHelpers.get_asset(a)
                if (self.unreal_texture_compression_settings):
                    t.compression_settings = self.unreal_texture_compression_settings

            if (not self.asset.use_srgb):
                t.srgb = False

            unreal.EditorAssetLibrary.save_loaded_asset(t,
                                                        only_if_is_dirty=False)

            # create the metadata file
            metadata = {
                "last_import": str(datetime.datetime.now().timestamp()),
                "source_path": self.asset.asset_library_path
            }

            os.chmod(unreal_path, stat.S_IREAD)

        else:
            print("Not in unreal!")
            print(tools_library.program_context())
Beispiel #3
0
    def create_menu(name, friendly_name):
        """Create the base menu"""
        # designer
        if (tools_library.program_context() == "designer"):
            import sd
            uimgr = sd.getContext().getSDApplication().getQtForPythonUIMgr()
            menu = QtWidgets.QMenu(name, None)
            menu.setObjectName(friendly_name)
            uimgr.newMenu(friendly_name, name)
            return uimgr.findMenuFromObjectName(name)

        # ue4
        elif (tools_library.program_context() == "ue4"):
            import unreal
            menus = unreal.ToolMenus.get()
            main_menu = menus.find_menu("LevelEditor.MainMenu")
            tools_library_menu = main_menu.add_sub_menu(
                main_menu.get_name(), friendly_name, friendly_name,
                friendly_name)
            tools_library_menu.searchable = True
            menus.refresh_all_widgets()
            return tools_library_menu

        # max
        elif (program_context == "max"):
            import qtmax
            import pymxs
            toolbar = qtmax.GetQMaxMainWindow()

            for i in list(toolbar.menuBar().actions()):
                if (i.text() == "ToolsLibrary"):
                    toolbar.menuBar().removeAction(i)

            main_menu = QtWidgets.QMenu("ToolsLibrary", toolbar)
            main_menu.setObjectName("ToolsLibrary")
            toolbar.menuBar().addMenu(main_menu)
            return main_menu

        return None
Beispiel #4
0
 def run_import(self):
     """"""
     import tools_library
     if (tools_library.program_context() != "ue4"):
         import tools_library.ue4
         import textwrap
         command = textwrap.dedent(f"""
             import asset_library.asset_types.geometry.manager
             asset_library.asset_types.geometry.manager.GeometryManager.run_import()
         """)
         tools_library.ue4.send_command(command)
     else:
         for i in self.get_geometry_paths():
             geo = Geometry(i)
             geo.ue4.run_import()
Beispiel #5
0
    def initialize_menu(menu):
        """Add all macros/groups to the menu"""
        append_menu(menu,
                    branches=None,
                    macros=tools_library.framework.programs._ProgramData(
                        tools_library.program_context()).get_macros())

        add_separator(menu)

        for i in tools_library.framework.plugins.plugin_dirs():
            plugin_name = os.path.basename(i)
            plugin = tools_library.framework.plugins._PluginData(plugin_name)
            if (plugin.enabled):
                macros = plugin.get_macros()
                append_menu(menu, branches=None, macros=macros)

        add_separator(menu)

        core_macros = tools_library.framework.programs._BackendData(
        ).get_core_macros()
        for i in core_macros:
            add_action(menu, i)
Beispiel #6
0
    def run_import(self):
        """Import the current material to unreal"""
        import tools_library
        if (tools_library.program_context() != "ue4"):
            self.asset.save()
            import tools_library.ue4 as ue
            import textwrap
            command = textwrap.dedent(f"""
                import asset_library.asset_types.material
                mat = asset_library.asset_types.material.Material(\"{self.asset.real_path}\")
                mat.ue4.run_import()
                """)
            ue.send_command(command)
            return

        import unreal
        import tools_library.ue4.materials.material_instance

        textures = self.asset.textures
        for tex in self.asset.textures:
            tex.ue4.run_import()

        # create unreal material
        mat_unreal_path = self.unreal_relative_path
        mi_name = os.path.basename(mat_unreal_path)
        mi_dir = os.path.dirname(mat_unreal_path)
        if (unreal.EditorAssetLibrary.does_asset_exist(mat_unreal_path)):
            new_mi = unreal.EditorAssetLibrary.find_asset_data(
                mat_unreal_path).get_asset()
        else:
            asset_tools = unreal.AssetToolsHelpers.get_asset_tools()
            new_mi = asset_tools.create_asset(
                mi_name, mi_dir, unreal.MaterialInstanceConstant,
                unreal.MaterialInstanceConstantFactoryNew())

        target_shader = self.asset.get_parent_shader()

        if (not target_shader):
            target_shader = Shader(
                "X:\\Shaders\\Surface_Standard\\SHD_Surface_Standard.shader")

        upath = target_shader.ue4.unreal_relative_path
        parent_mat = unreal.EditorAssetLibrary.find_asset_data(upath)
        unreal.MaterialEditingLibrary.set_material_instance_parent(
            new_mi, parent_mat.get_asset())

        for i in textures:
            param_name = i.texture_parameter_name
            if (param_name):
                tools_library.ue4.materials.material_instance.set_texture(
                    new_mi, param_name, i.ue4.unreal_relative_path)

        for i in self.asset.data["parameters"]:
            tools_library.ue4.materials.material_instance.set_parameter(
                new_mi, i, self.asset.data["parameters"][i])

        if (self.asset.two_sided):
            base_property_overrides = new_mi.get_editor_property(
                "base_property_overrides")
            base_property_overrides.set_editor_property("two_sided", True)
            base_property_overrides.set_editor_property(
                "override_two_sided", True)
            new_mi.set_editor_property("base_property_overrides",
                                       base_property_overrides)

        saved = unreal.EditorAssetLibrary.save_loaded_asset(
            new_mi, only_if_is_dirty=False)
Beispiel #7
0
import os
import sys
from functools import partial
from PySide2 import QtCore, QtGui, QtWidgets
import subprocess
import textwrap

import tools_library
import tools_library.framework.plugins
import tools_library.framework.programs
import tools_library.utilities.string as string_utils

branch_menus = {}
program_context = tools_library.program_context()

if (program_context not in ["python", "painter"]):

    def add_separator(menu):
        """Add a separator to the menu"""
        if (program_context in ["designer", "max"]):
            menu.addSeparator()

        elif (program_context == "ue4"):
            pass

    def add_action(parent, macro):
        """Add a macro as an action to the menu
        :param <menu:parent> The parent menu
        :param <Macro:macro> The macro to add
        """
        action = None
Beispiel #8
0
    def run_import(self):
        try:
            if (tools_library.program_context() != "ue4"):
                self.asset.save()
                import tools_library.ue4 as ue
                import textwrap
                command = textwrap.dedent(f"""
                    import asset_library.asset_types.geometry.geometry
                    geo = asset_library.asset_types.geometry.geometry.Geometry(\"{self.asset.real_path}\")
                    geo.ue4.run_import()
                    """)
                ue.send_command(command)
                return

            else:
                # import all materials for the mesh
                for i in self.asset.materials:
                    i.ue4.run_import()

                # import the geometry
                import unreal

                fbx_options = unreal.FbxImportUI()
                fbx_options.set_editor_property("import_mesh", True)
                fbx_options.set_editor_property("import_as_skeletal", False)
                fbx_options.import_as_skeletal = False
                fbx_options.set_editor_property("import_textures", False)
                fbx_options.set_editor_property("import_materials", False)
                fbx_options.set_editor_property("import_rigid_mesh", False)
                fbx_options.set_editor_property(
                    "mesh_type_to_import",
                    unreal.FBXImportType.FBXIT_STATIC_MESH)
                fbx_options.set_editor_property(
                    "original_import_type",
                    unreal.FBXImportType.FBXIT_STATIC_MESH)
                fbx_options.set_editor_property("physics_asset", None)
                fbx_options.set_editor_property(
                    "reset_to_fbx_on_material_conflict", True)
                fbx_options.static_mesh_import_data.set_editor_property(
                    "combine_meshes", True)
                fbx_options.static_mesh_import_data.set_editor_property(
                    "reorder_material_to_fbx_order", True)

                task = unreal.AssetImportTask()
                task.set_editor_property('automated', True)
                task.set_editor_property('filename', self.asset.fbx_path)
                task.set_editor_property(
                    'destination_path',
                    os.path.dirname(self.unreal_relative_path))
                task.set_editor_property('destination_name', "")
                task.set_editor_property('replace_existing', True)
                task.set_editor_property('save', True)
                task.set_editor_property('options', fbx_options)

                unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks(
                    [task])

                # ..
                uasset = self.unreal_asset

                # set the materials on the .uasset
                materials_ = self.asset.materials
                for i in range(len(materials_)):
                    mat = materials_[i]
                    uasset.set_material(i, mat.ue4.unreal_asset)
        except:
            asset_library.log.error(
                f"Failed to import material {self.asset.name}")