def import_files(selected_files): tasks_list = [] for f in selected_files: tasks_list.append(create_import_task(f)) ue.AssetToolsHelpers.get_asset_tools().import_asset_tasks(tasks_list) first_imported_object = None # Post-import assets editing for t in tasks_list: for objectPath in t.imported_object_paths: # Controlla di che tipo di asset si tratta e se texture cambia il compression setting in modo appropriato file_type = parse_filename_parts(t.filename)[1] if file_type in ['tga', 'png', 'psd', 'jpg']: texture_type = parse_filename_parts(t.filename)[3] if texture_type == 'M': # MASKS mask_texture = ue.EditorAssetLibrary.load_asset(objectPath) mask_texture.compression_settings = ue.TextureCompressionSettings.TC_MASKS mask_texture.srgb = False elif texture_type == 'N': # NORMAL MAP normal_texture = ue.EditorAssetLibrary.load_asset( objectPath) normal_texture.compression_settings = ue.TextureCompressionSettings.TC_NORMALMAP elif texture_type == 'UI': # USER INTERFACE ui_texture = ue.EditorAssetLibrary.load_asset(objectPath) ui_texture.compression_settings = ue.TextureCompressionSettings.TC_EDITOR_ICON elif texture_type in ('A', 'O', 'AO'): # SINGLE GRAYSCALE MASK grayscale_texture = ue.EditorAssetLibrary.load_asset( objectPath) grayscale_texture.compression_settings = ue.TextureCompressionSettings.TC_GRAYSCALE elif texture_type in ('V', 'FM'): # VECTOR DISPLACEMENT vector_texture = ue.EditorAssetLibrary.load_asset( objectPath) vector_texture.compression_settings = ue.TextureCompressionSettings.TC_VECTOR_DISPLACEMENTMAP elif texture_type == 'H': # HDR hdr_texture = ue.EditorAssetLibrary.load_asset(objectPath) hdr_texture.compression_settings = ue.TextureCompressionSettings.TC_HDR if not first_imported_object: first_imported_object = objectPath ue.EditorAssetLibrary().load_asset(first_imported_object) print(get_asset_base_name(first_imported_object)) ue.EditorAssetLibrary().sync_browser_to_objects([ first_imported_object, ])
def SpawnSurroundingActor(ActorToSpawn, Core, CenterObject, Distance=10, NumberOfWalls=0) : if NumberOfWalls <= 0 : NumberOfWalls = Distance spawningActorAsset = unreal.EditorAssetLibrary().find_asset_data(ActorToSpawn) spawningActorObject = spawningActorAsset.get_asset() level_actor_list = unreal.EditorLevelLibrary().get_all_level_actors() for a in level_actor_list: if a.get_name() == Core : core_object = a if a.get_name() == CenterObject : center_object = a ForwardVector = center_object.get_actor_forward_vector() PerpendicularVector = unreal.Vector(1, 1, ((ForwardVector.x + ForwardVector.y) * -1) / ForwardVector.z ) PerpendicularVector = PerpendicularVector * Distance NewPosition = PerpendicularVector + center_object.get_actor_location() RotationAxis = center_object.get_actor_location() - core_object.get_actor_location() with unreal.ScopedEditorTransaction("Spawn Surrounding Actors") as trans: for i in range(0, NumberOfWalls, 2) : ResultPosition = unreal.MathLibrary().rotate_angle_axis(NewPosition, i * 360 / Distance, RotationAxis) unit_direction = unreal.MathLibrary().get_direction_unit_vector(core_object.get_actor_location(), ResultPosition) ResultLocation = (unit_direction * 590) + core_object.get_actor_location() spawned_actor = unreal.EditorLevelLibrary().spawn_actor_from_object(spawningActorObject, ResultLocation) spawned_actor.set_actor_relative_scale3d(unreal.Vector(0.1, 0.1, 2.0)) spawned_actor.set_actor_rotation(GetCoreBasedRotation(core_object.get_actor_location(), spawned_actor), True)
def find_no_use_assets(): for asset in list_assets: u_eal = unreal.EditorAssetLibrary() asset_data = u_eal.find_asset_data(asset) for num in range(len(check_list)): if asset_data.asset_class == check_list[num]: ref = u_eal.find_package_referencers_for_asset(asset) if not ref: lists[num].append(asset)
def setup_output(self): asset_editor = unreal.AssetEditorSubsystem() editor_asset = unreal.EditorAssetLibrary() with open("{}BitBaker/Content/Python/ConsoleLog.txt".format(plugin_dir), "r") as Log: broken_assets = [] lines = Log.readlines() for line in lines: asset_paths = line.rstrip() asset_paths = asset_paths.split('|') self.output_log.addItem(str(asset_paths[0])) print(asset_paths)
import unreal import os # instances of unreal classes editor_util = unreal.EditorUtilityLibrary() system_lib = unreal.SystemLibrary() editor_asset_lib = unreal.EditorAssetLibrary() # get the selected assets selected_assets = editor_util.get_selected_assets() num_assets = len(selected_assets) cleaned = 0 # hard coded parent path parent_dir = "\\Game" if num_assets > 0: asset_path = editor_asset_lib.get_path_name_for_loaded_asset( selected_assets[0]) parent_dir = os.path.dirname(asset_path) for asset in selected_assets: # get the class instance and the clear text name asset_name = system_lib.get_object_name(asset) asset_class = asset.get_class() class_name = system_lib.get_class_display_name(asset_class) # assemble new path and relocate assets try: new_path = os.path.join(parent_dir, class_name, asset_name) editor_asset_lib.rename_loaded_asset(asset, new_path)
def import_file_from_task(import_task): if import_task: try: ue.AssetToolsHelpers.get_asset_tools().import_asset_tasks( [import_task]) imported_asset = None # Post-import assets editing for objectPath in import_task.imported_object_paths: # Controlla di che tipo di asset si tratta e se texture cambia il compression setting in modo appropriato file_type = parse_filename_parts(import_task.filename)[1] print("filetype: ") print(file_type) if file_type in ['tga', 'png', 'psd', 'jpg']: texture_type = parse_filename_parts( import_task.filename)[3] if texture_type == 'M': # MASKS mask_texture = ue.EditorAssetLibrary.load_asset( objectPath) mask_texture.compression_settings = ue.TextureCompressionSettings.TC_MASKS mask_texture.srgb = False elif texture_type == 'N': # NORMAL MAP normal_texture = ue.EditorAssetLibrary.load_asset( objectPath) normal_texture.compression_settings = ue.TextureCompressionSettings.TC_NORMALMAP elif texture_type == 'UI': # USER INTERFACE ui_texture = ue.EditorAssetLibrary.load_asset( objectPath) ui_texture.compression_settings = ue.TextureCompressionSettings.TC_EDITOR_ICON elif texture_type in ('A', 'O', 'AO'): # SINGLE GRAYSCALE MASK grayscale_texture = ue.EditorAssetLibrary.load_asset( objectPath) grayscale_texture.compression_settings = ue.TextureCompressionSettings.TC_GRAYSCALE elif texture_type in ('V', 'FM'): # VECTOR DISPLACEMENT vector_texture = ue.EditorAssetLibrary.load_asset( objectPath) vector_texture.compression_settings = ue.TextureCompressionSettings.TC_VECTOR_DISPLACEMENTMAP elif texture_type == 'H': # HDR hdr_texture = ue.EditorAssetLibrary.load_asset( objectPath) hdr_texture.compression_settings = ue.TextureCompressionSettings.TC_HDR elif file_type == "fbx": mesh = ue.EditorAssetLibrary.load_asset(objectPath) print(mesh) new_material = ue.EditorAssetLibrary.load_asset( "/Game/City20/Core/Graphics/Materials/ProceduralPalette/MI_City20Palette_01_Static_Opaque" ) print(new_material) mesh.set_material( mesh.get_material_index("MI_City20Palette_01"), new_material) if not imported_asset: imported_asset = objectPath ue.EditorAssetLibrary().load_asset(imported_asset) print(get_asset_base_name(imported_asset)) ue.EditorAssetLibrary().sync_browser_to_objects([ imported_asset, ]) return True except: return False
# SPDX-License-Identifier: BSD-3-Clause # Rodrigo Nascimento Hernandez # Tested UE versions: # 4.26.1 # Blueprint: ImportLines import sys import json import unreal # ========================================= user inputs =============================================================== # Change this path pointing to your gdal python bindings install dir sys.path.append(r'C:\OSGeo4W64\apps\Python37\Lib\site-packages') from osgeo import ogr # Set project's relative path of the importlines BluePrint (e.g. in content folder-> importlines = unreal.EditorAssetLibrary().load_blueprint_class( '/Game/ImportLines') # Set shapefile path shapefile = r'D:\UnrealEngine\curves\contour.shp' # Set layer's feature name to read lines vertices Z values (height). Leave empty to not import any (Can use blueprint's 'Snap to Ground' custom event instead) # If set to read Z values so you need to set 'Height point reference (m)' value also, calculated by 'srtm2heightmap.py' featurename = '' hpointreference = 572 # Set real world's UTM X,Y Origin (used in srtm2heightmap.py e.g.) UTMx = 596441.4895549538 UTMy = 7918815.581869906 # Choose one of SplinePointType to be used on import SplinePointType = unreal.SplinePointType.CURVE_CLAMPED # SplinePointType = unreal.SplinePointType.CURVE_CUSTOM_TANGENT # SplinePointType = unreal.SplinePointType.LINEAR # SplinePointType = unreal.SplinePointType.CURVE # SplinePointType = unreal.SplinePointType.CONSTANT
import unreal project_id = "000" project_name = "MaterialsTest" prefix = ["SE", "SM"] sub_directories = ["materials", "textures", "meshes", "blueprints"] directory = unreal.EditorAssetLibrary() directory_path = "/Game/" + prefix[0] + project_id + "_" + project_name level = unreal.EditorLevelLibrary() level_name = prefix[1] + "_" + project_name level_asset = directory_path + "/" + level_name def make_directory(): does_exist = True if directory.does_directory_exist == does_exist: print(str(directory_path) + ' already exists') else: directory.make_directory(directory_path) for i in sub_directories: directory.make_directory(directory_path + "/" + i) print(str(directory_path) + ' created') make_directory()
import os import unreal editor_utility = unreal.EditorUtilityLibrary() asset_editor = unreal.AssetEditorSubsystem() editor_asset = unreal.EditorAssetLibrary() asset_registry_helper = unreal.AssetRegistryHelpers() gameplay_statics = unreal.GameplayStatics() editor_level = unreal.EditorLevelLibrary() def open_asset(): assets = [] selected_assets = editor_utility.get_selected_assets() for asset in selected_assets: assets.append(asset) asset_editor.open_editor_for_assets(assets) def setup_output(): with open("D:/NekoNeko/Plugins/BitBaker/Content/Python/ConsoleLog.txt".format(os.path.dirname(__file__)), "r") as Log: broken_assets = [] lines = Log.readlines() for line in lines: asset_paths = line.rstrip() asset_paths = asset_paths.split('|') print(asset_paths) # Checks if there's a Map file extension in the errors, if so don't try to load it. # Do this by splitting the '.' and getting the last string in the asset_paths get_extension = asset_paths[0].split('.') if get_extension[-1] != 'umap':
def importAsset(self, targetDir): import xml.etree.ElementTree as ET root = ET.parse(targetDir + '\\Description.xml').getroot() # print textureTargetNameList textureTargetNameList = [] material_template_lists = list() for elem in root.iter(): if (elem.tag == "Material"): material = elem.attrib.get('matName') material_template_path, material_template = self.get_material_template( material) if not material_template: continue if material_template not in material_template_lists: material_template_lists.append(material_template) else: continue Minslots = set() for elem_Inst in elem.iter(): for Pic in elem_Inst.iter(): Usage = Pic.attrib.get('Usage') if Usage: Minslots.add(Usage) self.MaterialsTemplateArr.append({ 'mat_inst': material_template, 'mat_inst_path': material_template_path, 'Minslots': list(Minslots) }) # for template in self.MaterialsTemplateArr: # print('xx' + str(template)) # return # targetDir = 'M:\\DLQ2\\asset_work\\props\\hw\\Model\\texture\\publish' root = ET.parse(targetDir + '\\Description.xml').getroot() picList = [] destination_path = "/Game" + targetDir.replace("\\", "/").split(":")[1] importType = 0 # print os.path.exists('M:\\DLQ2\\asset_work\\props\\hw\\Model\\texture\\publish\\Description.xml') # print root,root.tag, root.attrib # for child_of_root in root: # print child_of_root.tag, child_of_root.attrib MeshFileName = "" is_character_type = False is_Combine_meshs = False dict_static_type = { 'Character': False, 'Environment': False, 'Props': False } for elem in root.iter(): # print elem.tag, elem.attrib if (elem.tag == "Pic"): Pic_Path = elem.attrib.get('Path') # print Pic_Path picList.append(Pic_Path) # destination_path = "/"+os.path.dirname(Pic_Path).replace('M:',"Game") elif (elem.tag == "StaticMesh"): MeshFileName = elem.attrib.get('Path') print('MeshFileName is {}'.format(MeshFileName)) static_type = elem.attrib.get('AssetType') dict_static_type[static_type] = True importType = 1 elif (elem.tag == "SkeletalMesh"): MeshFileName = elem.attrib.get('Path') print('MeshFileName is {}'.format(MeshFileName)) if elem.attrib.get('AssetType') == 'character': is_character_type = True importType = 2 # print "importType" + str(importType) self.importIMGAsset(picList, destination_path) #// by chenganggui EditorAssetLibrary = unreal.EditorAssetLibrary() AssetRegistry = unreal.AssetRegistryHelpers().get_asset_registry() # print "destination_path.replace" + destination_path if not EditorAssetLibrary.does_directory_exist(destination_path): EditorAssetLibrary.make_directory(destination_path) AssetRegistryDataArr = AssetRegistry.get_assets_by_path( destination_path) texArr = [] # print AssetRegistryDataArr for AssetRegistryData in AssetRegistryDataArr: # print AssetRegistryData.package_name # print 'AssetRegistryData.package_name '+ AssetRegistryData.package_name texArr.append(str(AssetRegistryData.package_name)) # print destination_path # print texArr for elem in root.iter(): if (elem.tag == "Material"): Material_matName = elem.attrib.get('matName') # print "Material_matName:: "+Material_matName Material_TemplateList = self.Material_Template.split("/") # print('Material_matName is {} '.format(Material_matName)) Pic_destination_path = destination_path self.create_material_instance(Material_matName, Pic_destination_path, texArr) # add by chenganggui # for f in os.listdir(targetDir): # # print f # if (f.find(".fbx") != -1): # MeshFileName = targetDir + "\\" + f # print MeshFileName if MeshFileName == "": print('canot find fbx file') return if importType == 1: package_path = "/Game" + os.path.dirname(targetDir).replace( "\\", "/").split(":")[1] package_path = package_path.replace(".", "_") # EditorAssetLibrary = unreal.EditorAssetLibrary() # if (EditorAssetLibrary.does_directory_exist(package_path)): # EditorAssetLibrary.delete_directory(package_path) if dict_static_type['Environment']: print('not conbine' + '**' * 10) self.importStaticMesh(MeshFileName, destination_path) # add by chenganggui else: print('need conbine' + '**' * 10) self.importStaticMesh( MeshFileName, destination_path, bCombine_meshs=True) # add by chenganggui print('package_path is {}'.format(package_path)) self.resetStaticMeshMaterial( package_path ) # '/Game/DLQ2/asset_work/props/hw/Model/texture/publish/image/hw_Texture_V01_fbx' # unreal.EditorLoadingAndSavingUtils.save_dirty_packages(True, True) elif importType == 2: package_path = "/Game" + os.path.dirname(targetDir).replace( "\\", "/").split(":")[1] package_path = package_path.replace(".", "_") # EditorAssetLibrary = unreal.EditorAssetLibrary() # if (EditorAssetLibrary.does_directory_exist(package_path)): # EditorAssetLibrary.delete_directory(package_path) print('import skeletal mesh') self.importSkeletalMesh(MeshFileName, destination_path) # self.resetSkeletonMeshMaterial( # package_path) # '/Game/DLQ2/asset_work/props/hw/Model/texture/publish/image/hw_Texture_V01_fbx' unreal.EditorLoadingAndSavingUtils.save_dirty_packages(True, True) #判断是否是character类型,所以为skeletalmesh 添加插槽 if is_character_type: print('this is is_character_type') self.add_slots(package_path)