def createTexture(self , filepath = '', importLocation = '' , overwrite = "" , textureName = "test"):
        import_tasks = []
        
        if overwrite == "y" or overwrite == "True" or overwrite == "yes" or overwrite == "Y" or overwrite == "TRUE" or overwrite == "true":
            replace = True
            
        else:
            replace = False
        if "." in textureName:
            textureName = textureName.split(".")[0]
        textureName = self.legalizeName(textureName)
        
        
        
        if unreal.EditorAssetLibrary.does_asset_exist(importLocation + '/' +  textureName):# or not replace:
            unreal.log_warning("texture " + textureName + " already exists, skipping")
        else:
            if not os.path.exists(filepath):
                if os.path.exists(os.path.join(UEImporter.rootImportFolder,filepath)):
                    filepath = os.path.join(UEImporter.rootImportFolder,filepath)
                else:
                    filepath = os.path.join(UEImporter.rootImportFolder,"textures",filepath)

        #unreal.log_error(filepath)    
        if os.path.exists(filepath):
            AssetImportTask = unreal.AssetImportTask()
            AssetImportTask.set_editor_property('filename', filepath)
            AssetImportTask.set_editor_property('destination_path', importLocation)
            AssetImportTask.set_editor_property('replace_existing',True)
            AssetImportTask.set_editor_property('save', True)
            import_tasks.append(AssetImportTask)
            self.AssetTools.import_asset_tasks(import_tasks) #import all textures
def create_import_task(filename, mirror_path=True):
    task = ue.AssetImportTask()
    task.filename = filename

    file_type = os.path.splitext(filename)[1][1:]
    """In base all'estensione cambia cosa fa l'importer:
    1- FBX: crea un FbxImportUI come options e imposta i vari parametri. Poi stabilisce da solo se importarla come Static o Skeletal
    2- TGA, PNG, PSD, JPG: importa come texture e in base al suffisso decide quale compressione applicare"""

    if file_type == 'fbx':
        print('MESH')
        task.options = ue.FbxImportUI()
        task.options.automated_import_should_detect_type = True
        task.options.create_physics_asset = False
        task.options.import_materials = False
        task.options.import_textures = True
        task.options.static_mesh_import_data.combine_meshes = True

    elif file_type in ['tga', 'png', 'psd', 'jpg']:
        print('TEXTURE')

    if mirror_path:
        print("path " + filename)
        task.destination_path = get_content_from_working_path(
            os.path.dirname(filename))
    else:
        task.destination_path = "/Game"  # Cambiare in modo che importi nella cartella attualmente selezionata
    task.automated = True
    return task
Exemple #3
0
    def _import_animation(self, path, sg_publish_data):
        skeleton = editor_util.get_selected_assets()[0]

        context = self.sgtk.context_from_entity_dictionary(sg_publish_data)
        name = os.path.basename(path).split(".")[0]
        destination_path = "/Game/Animation/{shot}/{name}".format(
            shot=context.entity["name"], name=name)

        task = unreal.AssetImportTask()
        task.filename = path
        task.destination_path = destination_path
        task.replace_existing = True
        task.automated = True
        task.save = True

        task.options = unreal.FbxImportUI()
        task.options.import_mesh = False
        task.options.import_materials = False
        task.options.create_physics_asset = False
        task.options.import_textures = False
        task.options.import_animations = True
        task.options.import_as_skeletal = False
        task.options.skeleton = skeleton
        task.options.mesh_type_to_import = unreal.FBXImportType.FBXIT_ANIMATION

        unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks([task])
Exemple #4
0
    def update(self, container, representation):
        node = container["objectName"]
        source_path = api.get_representation_path(representation)
        destination_path = container["namespace"]

        task = unreal.AssetImportTask()

        task.filename = source_path
        task.destination_path = destination_path
        # strip suffix
        task.destination_name = node[:-4]
        task.replace_existing = True
        task.automated = True
        task.save = True

        task.options = unreal.FbxImportUI()
        task.options.import_animations = False

        # do import fbx and replace existing data
        unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks([task])
        container_path = "{}/{}".format(container["namespace"],
                                        container["objectName"])
        # update metadata
        avalon_unreal.imprint(container_path,
                              {"_id": str(representation["_id"])})
Exemple #5
0
def create_fbx_import_task(fbx_path,
                           game_path,
                           asset_name,
                           import_options,
                           suppress_ui=True):
    """
    Creates a import task for the given fbx.

    :param str fbx_path: Path to import.
    :param str game_path: Path to import to.
    :param str asset_name: Name of the asset.
    :param FbxImportUI import_options: The import options for the import task.
    :param bool suppress_ui: Suppress the ui or not.
    :return: Returns the import task.
    :rtype: AssetImportTask.
    """
    # create an import task
    import_task = unreal.AssetImportTask()

    # set the base properties on the import task
    import_task.filename = fbx_path
    import_task.destination_path = game_path
    import_task.destination_name = asset_name
    import_task.automated = suppress_ui

    # set the import options on the import task
    import_task.options = import_options
    return import_task
def _generate_fbx_import_task(filename, destination_path, destination_name=None, replace_existing=True,
                             automated=True, save=True, materials=True,
                             textures=True, as_skeletal=False):
    """
    Create and configure an Unreal AssetImportTask

    :param filename: The fbx file to import
    :param destination_path: The Content Browser path where the asset will be placed
    :return the configured AssetImportTask
    """
    task = unreal.AssetImportTask()
    task.filename = filename
    task.destination_path = destination_path
    
    # By default, destination_name is the filename without the extension
    if destination_name is not None:
        task.destination_name = destination_name
        
    task.replace_existing = replace_existing
    task.automated = automated
    task.save = save

    task.options = unreal.FbxImportUI()
    task.options.import_materials = materials
    task.options.import_textures = textures
    task.options.import_as_skeletal = as_skeletal
    # task.options.static_mesh_import_data.combine_meshes = True

    task.options.mesh_type_to_import = unreal.FBXImportType.FBXIT_STATIC_MESH
    if as_skeletal:
        task.options.mesh_type_to_import = unreal.FBXImportType.FBXIT_SKELETAL_MESH

    return task
Exemple #7
0
    def buildImportTask(self, filename='', destination_path='', skeleton=None):

        options = unreal.FbxImportUI()
        options.set_editor_property("skeleton", skeleton)
        # NOTE 只导入 动画 数据
        options.set_editor_property("import_animations", True)
        options.set_editor_property("import_as_skeletal", False)
        options.set_editor_property("import_materials", False)
        options.set_editor_property("import_textures", False)
        options.set_editor_property("import_rigid_mesh", False)
        options.set_editor_property("create_physics_asset", False)
        options.set_editor_property("mesh_type_to_import",
                                    unreal.FBXImportType.FBXIT_ANIMATION)
        # NOTE https://forums.unrealengine.com/development-discussion/python-scripting/1576474-importing-skeletal-meshes-4-21
        options.set_editor_property("automated_import_should_detect_type",
                                    False)

        task = unreal.AssetImportTask()
        task.set_editor_property("factory", unreal.FbxFactory())
        # NOTE 设置 automated 为 True  不会弹窗
        task.set_editor_property("automated", True)
        task.set_editor_property("destination_name", '')
        task.set_editor_property("destination_path", destination_path)
        task.set_editor_property("filename", filename)
        task.set_editor_property("replace_existing", True)
        task.set_editor_property("save", False)
        task.options = options

        return task
def import_animation_fbx(animation_fbx_filename, skeleton):
    task = ue.AssetImportTask()
    task.filename = animation_fbx_filename

    task.options = ue.FbxImportUI()
    task.options.automated_import_should_detect_type = True
    task.options.mesh_type_to_import = ue.FBXImportType.FBXIT_SKELETAL_MESH
    # task.options.import_as_skeletal = False
    task.options.skeleton = ue.load_asset(skeleton)
    task.options.import_mesh = False
    task.options.import_animations = True
    task.options.create_physics_asset = False
    task.options.import_materials = False
    task.options.import_textures = False
    task.destination_path = get_content_from_working_path(
        os.path.dirname(animation_fbx_filename))
    task.automated = True

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

    # remove not needed mesh asset and rename animation clip
    # THIS IS A TEMP FIX UNTIL import_meshes=False WON'T WORK
    base_name = os.path.basename(animation_fbx_filename).replace(".fbx", "")
    ue.EditorAssetLibrary.delete_asset(task.destination_path + "/" + base_name)
    ue.EditorAssetLibrary.rename_asset(
        task.destination_path + "/" + base_name + "_Anim",
        task.destination_path + "/" + base_name)
Exemple #9
0
def import_skeletal_mesh(fbx_path, game_path, asset_name):
    """
    Import a single skeletalMesh into the engine provided an FBX.

    :param str fbx_path: Path to fbx.
    :param str game_path: Game path asset location.
    :param str asset_name: Name of asset.
    :return:
    """
    # Create an import task.
    import_task = unreal.AssetImportTask()

    # Set base properties on the import task.
    import_task.filename = fbx_path
    import_task.destination_path = game_path
    import_task.destination_name = asset_name
    import_task.automated = True  # Suppress UI.

    # Set the skeletal mesh options on the import task.
    import_task.options = _get_skeletal_mesh_import_options()

    # Import the skeletalMesh.
    unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks(
        [import_task]  # Expects a list for multiple import tasks.
    )
    imported_assets = import_task.get_editor_property("imported_object_paths")

    if not imported_assets:
        unreal.log_warning("No assets were imported!")
        return

    # Return the instance of the imported SkeletalMesh
    return unreal.load_asset(imported_assets[0])
def make_alembic_import_task(filepath, destination_path, save=True):
    task = unreal.AssetImportTask()
    task.set_editor_property("filename", filepath)
    task.set_editor_property("destination_path", destination_path)
    task.set_editor_property("replace_existing", True)
    task.set_editor_property("automated", True)
    task.set_editor_property("save", True)
    return task
def import_asset(asset_filepath, asset_destination_path):
    package_path, asset_name = split_path(asset_destination_path)
    asset_tools = unreal.AssetToolsHelpers.get_asset_tools()
    import_data = unreal.AssetImportTask()
    import_data.filename = asset_filepath
    import_data.destination_name = asset_name
    import_data.destination_path = package_path
    import_data.replace_existing = True
    asset_tools.import_asset_tasks([import_data])
def bulidImportTask(filename, destination_path):
    task = unreal.AssetImportTask()
    task.set_editor_property('automated', True)
    task.set_editor_property('destination_name', '')
    task.set_editor_property('destination_path', destination_path)
    task.set_editor_property('filename', filename)
    task.set_editor_property('replace_existing', True)
    task.set_editor_property('save', True)
    return task
Exemple #13
0
def buildImportTask(filename, destination_path):
    task = unreal.AssetImportTask()
    task.set_editor_property("automated", True)
    task.set_editor_property("destination_name", "QIU")
    task.set_editor_property("destination_path", destination_path)
    task.set_editor_property("filename", filename)
    task.set_editor_property("replace_existing", False)
    task.set_editor_property("save", True)
    return task
Exemple #14
0
def texture_import(single_texture):
    # import
    import_task = unreal.AssetImportTask()
    import_task.automated = True
    import_task.replace_existing = True
    import_task.filename = single_texture
    import_task.destination_path = Unreal_Folder
    unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks(
        [import_task])
Exemple #15
0
    def load(self, context, name, namespace, data):
        """
        Load and containerise representation into Content Browser.

        This is two step process. First, import FBX to temporary path and
        then call `containerise()` on it - this moves all content to new
        directory and then it will create AssetContainer there and imprint it
        with metadata. This will mark this path as container.

        Args:
            context (dict): application context
            name (str): subset name
            namespace (str): in Unreal this is basically path to container.
                             This is not passed here, so namespace is set
                             by `containerise()` because only then we know
                             real path.
            data (dict): Those would be data to be imprinted. This is not used
                         now, data are imprinted by `containerise()`.

        Returns:
            list(str): list of container content
        """

        tools = unreal.AssetToolsHelpers().get_asset_tools()
        temp_dir, temp_name = tools.create_unique_asset_name(
            "/Game/{}".format(name), "_TMP")

        unreal.EditorAssetLibrary.make_directory(temp_dir)

        task = unreal.AssetImportTask()

        task.filename = self.fname
        task.destination_path = temp_dir
        task.destination_name = name
        task.replace_existing = False
        task.automated = True
        task.save = True

        # set import options here
        task.options = unreal.FbxImportUI()
        task.options.import_animations = False

        unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks(
            [task])  # noqa: E501

        imported_assets = unreal.EditorAssetLibrary.list_assets(
            temp_dir, recursive=True, include_folder=True)
        new_dir = avalon_unreal.containerise(name, namespace, imported_assets,
                                             context, self.__class__.__name__)

        asset_content = unreal.EditorAssetLibrary.list_assets(
            new_dir, recursive=True, include_folder=True)

        unreal.EditorAssetLibrary.delete_directory(temp_dir)

        return asset_content
Exemple #16
0
def buildImportTask(filename='', destination_path='', options=None):
    task = unreal.AssetImportTask()
    task.set_editor_property('automated', True)
    task.set_editor_property('destination_name', '')
    task.set_editor_property('destination_path', destination_path)
    task.set_editor_property('filename', filename)
    task.set_editor_property('replace_existing', True)
    task.set_editor_property('save', True)
    task.set_editor_property('options', options)
    return task
Exemple #17
0
def build_import_task(filename='', destination_path='', options=None):
    task = unreal.AssetImportTask()
    task.set_editor_property('automated', True)
    task.set_editor_property('destination_name', '')
    task.set_editor_property('destination_path', destination_path)
    task.set_editor_property('filename', filename)
    task.set_editor_property('replace_existing', True)
    task.set_editor_property('save', True)
    task.set_editor_property('options', options)
    filename = os.path.basename(os.path.splitext(filename)[0])
    return task, filename
Exemple #18
0
def build_import_task(filename, dest_path, options=None):
    # unreal.AssetImportTask    https://api.unrealengine.com/INT/PythonAPI/class/AssetImportTask.html
    task = unreal.AssetImportTask()
    task.set_editor_property('automated', True)
    task.set_editor_property('destination_name', '')
    task.set_editor_property('destination_path', dest_path)
    task.set_editor_property('filename', filename)
    task.set_editor_property('replace_existing', True)
    task.set_editor_property('save', True)
    # for Fbx Mesh
    task.set_editor_property('options', options)
    return task
Exemple #19
0
 def buildImportTask(self, filename, destination_path, options=None):
     task = unreal.AssetImportTask()
     # task = unreal.AutomatedAssetImportData()
     task.set_editor_property('automated', True)
     task.set_editor_property('destination_name', '')
     task.set_editor_property('destination_path', destination_path)
     task.set_editor_property('filename', filename)
     task.set_editor_property('replace_existing', True)
     task.set_editor_property('save', True)
     # task.set_editor_property('skip_read_only',True)
     task.set_editor_property('options', options)
     return task
Exemple #20
0
    def update(self, container, representation):
        name = container["asset_name"]
        source_path = api.get_representation_path(representation)
        destination_path = container["namespace"]

        task = unreal.AssetImportTask()

        task.set_editor_property('filename', source_path)
        task.set_editor_property('destination_path', destination_path)
        task.set_editor_property('destination_name', name)
        task.set_editor_property('replace_existing', True)
        task.set_editor_property('automated', True)
        task.set_editor_property('save', True)

        # set import options here
        options = unreal.FbxImportUI()
        options.set_editor_property('import_as_skeletal', True)
        options.set_editor_property('import_animations', False)
        options.set_editor_property('import_mesh', True)
        options.set_editor_property('import_materials', True)
        options.set_editor_property('import_textures', True)
        options.set_editor_property('skeleton', None)
        options.set_editor_property('create_physics_asset', False)

        options.set_editor_property('mesh_type_to_import',
                                    unreal.FBXImportType.FBXIT_SKELETAL_MESH)

        options.skeletal_mesh_import_data.set_editor_property(
            'import_content_type', unreal.FBXImportContentType.FBXICT_ALL)
        # set to import normals, otherwise Unreal will compute them
        # and it will take a long time, depending on the size of the mesh
        options.skeletal_mesh_import_data.set_editor_property(
            'normal_import_method',
            unreal.FBXNormalImportMethod.FBXNIM_IMPORT_NORMALS)

        task.options = options
        # do import fbx and replace existing data
        unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks(
            [task])  # noqa: E501
        container_path = "{}/{}".format(container["namespace"],
                                        container["objectName"])
        # update metadata
        unreal_pipeline.imprint(
            container_path, {
                "representation": str(representation["_id"]),
                "parent": str(representation["parent"])
            })

        asset_content = unreal.EditorAssetLibrary.list_assets(
            destination_path, recursive=True, include_folder=True)

        for a in asset_content:
            unreal.EditorAssetLibrary.save_asset(a)
Exemple #21
0
    def importHierarchyCSV(self):
        try:
            newname = self.fbxName.partition('.')[0]
            if newname[
                    0:
                    3] == "SM_":  #todo if there are any other prefixes in the future, test for them
                newname = "ASH_" + newname[3:]
            elif newname[
                    0:
                    4] == "CAM_":  #todo if there are any other prefixes in the future, test for them
                newname = "ASH_" + newname[4:]
            elif newname[
                    0:
                    4] == "LGT_":  #todo if there are any other prefixes in the future, test for them
                newname = "ASH_" + newname[4:]

            else:
                newname = "ASH_" + newname
            asset_name = newname

            import_tasks = []

            factory = unreal.CSVImportFactory()
            csvPath = self.rootImportFolder + asset_name + '.csv'  #todo at some point fix the hierarchy name so it is unique per import
            factory.script_factory_can_import(csvPath)  #

            AssetImportTask = unreal.AssetImportTask()
            AssetImportTask.set_editor_property('filename', csvPath)
            AssetImportTask.set_editor_property('factory', factory)
            AssetImportTask.set_editor_property('destination_path',
                                                self.UEMeshDirectory)
            AssetImportTask.set_editor_property('automated',
                                                True)  #self.automateImports)
            importSettings = unreal.CSVImportSettings()
            #importSettings.set_editor_property('import_row_struct',True)
            path_to_asset = '/OVFPPlugin/generalResources/blenderToUnrealAdgBridge/B2UADGBrige_MeshHierarcyCSV'  #.B2UADGBrige_MeshHierarcyCSV'
            asset_reg = unreal.AssetRegistryHelpers.get_asset_registry()
            #CSVstruct = asset_reg.get_asset_by_object_path(path_to_asset)
            CSVstruct = unreal.load_asset(path_to_asset)
            #unreal.log_warning(str(CSVstruct))
            factory.automated_import_settings.import_row_struct = CSVstruct

            #AssetImportTask.set_editor_property('save', False)
            import_tasks.append(AssetImportTask)

            #do the import
            self.AssetTools.import_asset_tasks(import_tasks)

            unreal.EditorAssetLibrary.save_directory(
                self.UEMeshDirectory)  #save directory we imported into
        except Exception:
            unreal.log("Issue with hierarcy file")
Exemple #22
0
    def CreateInstanceOfMaterial(self, materialFileName, newAssetName,
                                 destination_path, textureFileNameList,
                                 material_template):
        selectedAsset = unreal.load_asset(materialFileName)
        # newAssetName = ""
        # newAssetName = selectedAsset.get_name() + "_%s"
        # "_%s_%d"
        asset_import_task = unreal.AssetImportTask()
        asset_import_task.set_editor_property("save", True)
        asset_import_task.set_editor_property("automated", True)
        asset_import_task.set_editor_property("replace_existing", True)
        factory = unreal.MaterialInstanceConstantFactoryNew()
        factory.set_editor_property("asset_import_task", asset_import_task)
        factory.set_editor_property("create_new", True)
        asset_tools = unreal.AssetToolsHelpers.get_asset_tools()
        # createdAssetsPath = materialFileName.replace(selectedAsset.get_name(), "-")
        # createdAssetsPath = createdAssetsPath.replace("-.-", "")newAssetName %("inst")

        newAsset = asset_tools.create_asset(newAssetName, destination_path,
                                            None,
                                            factory)  # add by chenganggui
        unreal.MaterialEditingLibrary.set_material_instance_parent(
            newAsset, selectedAsset)  # add by chenganggui

        for textureFileName in textureFileNameList:
            for Minslot in material_template['Minslots']:
                if (textureFileName.find(Minslot) !=
                        -1) and newAssetName in textureFileName:
                    print(
                        'textureFileName is {}, Minslot is {}, newAsset is {}'.
                        format(textureFileName, Minslot, newAssetName))
                    texture_asset = unreal.Texture.cast(
                        unreal.load_asset(textureFileName))
                    unreal.MaterialEditingLibrary.set_material_instance_texture_parameter_value(
                        newAsset, Minslot, texture_asset)
        # for MaterialsTemplate in self.MaterialsTemplateArr:
        #     if (newAssetName.find(MaterialsTemplate['mat_Inst'].split("_")[0]) != -1):
        #         for textureFileName in textureFileNameList:
        #             # print "newAssetName::"+newAssetName+"  MaterialsTemplate.mat_Inst::"+MaterialsTemplate.mat_Inst+"  textureFileName::"+textureFileName+"  "
        #             for Minslot in MaterialsTemplate['Minslots']:
        #
        #                 if (textureFileName.find(Minslot) != -1) and newAssetName[:-5] in textureFileName:
        #                     # print('textureFileName is {} minslot is {}, newAssetName is {}'.format(
        #                     #     textureFileName,
        #                     #     Minslot,
        #                     #     newAssetName[:-5]
        #                     # ))
        #                     texture_asset = unreal.Texture.cast(unreal.load_asset(textureFileName))
        #                     unreal.MaterialEditingLibrary.set_material_instance_texture_parameter_value(newAsset,
        #                                                                                                 Minslot,
        #                                                                                                 texture_asset)
        unreal.EditorLoadingAndSavingUtils.save_dirty_packages(True, True)
Exemple #23
0
def buildImportTask(filename='', destination_path='', options=None):
    # https://docs.unrealengine.com/en-US/PythonAPI/class/AssetImportTask.html?highlight=assetimporttask
    task = unreal.AssetImportTask() # 包含要导入的一组资产的数据
    task.automated = True # 避免对话框
    task.destination_name = '' # 导入为的可选自定义名称
    task.destination_path = destination_path # 项目内容目录中将要导入资产的内容路径
    task.filename = filename # 要导入的文件名
    task.replace_existing = True # 覆盖现有资产
    task.options = options # (对象) – [读写]特定于资产类型的导入选项
    task.save = True # 导入后保存
    
    # task.imported_object_paths # (Array(str)):[读写]导入后创建或更新的对象的路径
    return task
def import_data_table_as_json(filename):
    task = unreal.AssetImportTask()
    task.filename = filename
    task.destination_path = "/Game/DataTables"
    task.replace_existing = True
    task.automated = True
    task.save = False
 
    task.factory = unreal.ReimportDataTableFactory()
    task.factory.automated_import_settings.import_row_struct = unreal.load_object(None, '/Game/DataTables/S_TestStruct.S_TestStruct')
    task.factory.automated_import_settings.import_type = unreal.CSVImportType.ECSV_DATA_TABLE
 
    unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks([task])
Exemple #25
0
    def update(self, container, representation):
        name = container["asset_name"]
        source_path = api.get_representation_path(representation)
        destination_path = container["namespace"]

        task = unreal.AssetImportTask()
        task.options = unreal.FbxImportUI()

        task.set_editor_property('filename', source_path)
        task.set_editor_property('destination_path', destination_path)
        # strip suffix
        task.set_editor_property('destination_name', name)
        task.set_editor_property('replace_existing', True)
        task.set_editor_property('automated', True)
        task.set_editor_property('save', False)

        # set import options here
        task.options.set_editor_property('automated_import_should_detect_type',
                                         True)
        task.options.set_editor_property('original_import_type',
                                         unreal.FBXImportType.FBXIT_ANIMATION)
        task.options.set_editor_property('import_mesh', False)
        task.options.set_editor_property('import_animations', True)

        task.options.skeletal_mesh_import_data.set_editor_property(
            'import_content_type',
            unreal.FBXImportContentType.FBXICT_SKINNING_WEIGHTS)

        skeletal_mesh = unreal.EditorAssetLibrary.load_asset(
            container.get('namespace') + "/" + container.get('asset_name'))
        skeleton = skeletal_mesh.get_editor_property('skeleton')
        task.options.set_editor_property('skeleton', skeleton)

        # do import fbx and replace existing data
        unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks([task])
        container_path = "{}/{}".format(container["namespace"],
                                        container["objectName"])
        # update metadata
        unreal_pipeline.imprint(
            container_path, {
                "representation": str(representation["_id"]),
                "parent": str(representation["parent"])
            })

        asset_content = unreal.EditorAssetLibrary.list_assets(
            destination_path, recursive=True, include_folder=True)

        for a in asset_content:
            unreal.EditorAssetLibrary.save_asset(a)
Exemple #26
0
def import_texture(filename, contentpath):
    task = unreal.AssetImportTask()
    task.set_editor_property('filename', filename)
    task.set_editor_property('destination_path', contentpath)
    task.automated = True

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

    asset_paths = task.get_editor_property("imported_object_paths")
    if not asset_paths:
        unreal.log_warning("No assets were imported!")
        return None

    return unreal.load_asset(asset_paths[0])
	def CreateTask_SK_GlovesArmor():
		################[ Import GlovesArmor as SkeletalMesh type ]################
		print('================[ New import task : GlovesArmor as SkeletalMesh type ]================')
		FilePath = os.path.join(r'D:\Users\97ran\Documents\Unreal Projects\Lowpoly_Journey\Blender\SK_ArmorModulars\ExportedFbx\SkeletalMesh\GlovesArmor\SK_GlovesArmor.fbx')
		AdditionalParameterLoc = os.path.join(r'D:\Users\97ran\Documents\Unreal Projects\Lowpoly_Journey\Blender\SK_ArmorModulars\ExportedFbx\SkeletalMesh\GlovesArmor\SK_GlovesArmor_AdditionalParameter.ini')
		AssetImportPath = (os.path.join(unrealImportLocation, r'').replace('\\','/')).rstrip('/')
		task = unreal.AssetImportTask()
		task.filename = FilePath
		task.destination_path = AssetImportPath
		task.automated = True
		task.save = True
		task.replace_existing = True
		task.set_editor_property('options', unreal.FbxImportUI())
		task.get_editor_property('options').set_editor_property('original_import_type', unreal.FBXImportType.FBXIT_SKELETAL_MESH)
		task.get_editor_property('options').set_editor_property('import_materials', True)
		task.get_editor_property('options').set_editor_property('import_textures', False)
		task.get_editor_property('options').set_editor_property('import_animations', False)
		task.get_editor_property('options').set_editor_property('create_physics_asset', True)
		task.get_editor_property('options').set_editor_property('import_animations', False)
		task.get_editor_property('options').set_editor_property('import_mesh', True)
		task.get_editor_property('options').set_editor_property('create_physics_asset', True)
		task.get_editor_property('options').texture_import_data.set_editor_property('material_search_location', unreal.MaterialSearchLocation.LOCAL)
		task.get_editor_property('options').skeletal_mesh_import_data.set_editor_property('import_morph_targets', True)
		task.get_editor_property('options').skeletal_mesh_import_data.set_editor_property('convert_scene', True)
		print('================[ import asset : GlovesArmor ]================')
		unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks([task])
		if len(task.imported_object_paths) > 0:
			asset = unreal.find_asset(task.imported_object_paths[0])
		else:
			asset = None
		if asset == None:
			ImportFailList.append('Asset "GlovesArmor" not found for after inport')
			return
		print('========================= Imports of GlovesArmor completed ! Post treatment started...	=========================')
	
		#Import the SkeletalMesh socket(s)
		sockets_to_add = GetOptionByIniFile(AdditionalParameterLoc, 'Sockets', True)
		skeleton = asset.get_editor_property('skeleton')
		for socket in sockets_to_add:
			pass
	
		#Import the SkeletalMesh lod(s)
		lods_to_add = GetOptionByIniFile(AdditionalParameterLoc, 'LevelOfDetail')
		for x, lod in enumerate(lods_to_add):
			pass
		print('========================= Post treatment of GlovesArmor completed !	 =========================')
		unreal.EditorAssetLibrary.save_loaded_asset(asset)
		ImportedList.append([asset, 'SkeletalMesh'])
Exemple #28
0
    def create_import_task(self, entity):
        """

        :param entity: ImportData instance
        :return:
        """
        options = self.build_import_options()

        task = unreal.AssetImportTask()
        task.set_editor_property('options', options)
        task.set_editor_property('automated', True)
        task.set_editor_property('filename', entity.to_string())
        task.set_editor_property('destination_name', entity.name)
        task.set_editor_property('destination_path', self.destination_path)
        task.set_editor_property('save', True)
        task.set_editor_property('replace_existing', True)
        return task
Exemple #29
0
def buildImportTask(filename='', destination_path=''):
    options = unreal.FbxImportUI()
    options.set_editor_property("mesh_type_to_import",
                                unreal.FBXImportType.FBXIT_STATIC_MESH)

    task = unreal.AssetImportTask()
    task.set_editor_property("factory", unreal.FbxFactory())
    name = os.path.basename(os.path.splitext(filename)[0])
    # NOTE 设置 automated 为 True  不会弹窗
    task.set_editor_property("automated", True)
    task.set_editor_property("destination_name", name)
    task.set_editor_property("destination_path", destination_path)
    task.set_editor_property("filename", filename)
    task.set_editor_property("replace_existing", True)
    task.set_editor_property("save", False)
    task.options = options
    return task
def buildImportTask(fileName, destination_path):
    task = unreal.AssetImportTask()
    # 避免对话框
    task.set_editor_property('automated', True)

    # 导入之后的路径
    task.set_editor_property('destination_path', destination_path)

    # 导入的文件
    task.set_editor_property('filename', fileName)

    # 覆盖
    task.set_editor_property('replace_existing', True)
    # 保存
    task.set_editor_property('save', True)

    return task