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"])})
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
def get_basic_skeletal_import_options(import_method=None, import_materials=False, import_textures=False): """ Get some basic default import options for a SkeletalMesh import. :param int or enum import_method: The normals import method. :param bool import_materials: Whether to import the materials or not. :param bool import_textures: Whether to import the textures or not. :return: Returns the import options. :rtype: unreal.FbxImportUI """ # create the options handle options = unreal.FbxImportUI() # set to import as skeletal options.import_as_skeletal = True options.mesh_type_to_import = ImportTypes.SKELETAL_MESH # determine and set the import option for normals import_method = import_method or ImportOptions.COMPUTE options.skeletal_mesh_import_data.import_method = import_method # determine and set whether to import materials and textures options.import_materials = import_materials or False options.import_textures = import_textures or False return options
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)
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])
def build_import_options(): options = unreal.FbxImportUI() # ---- MESH options.set_editor_property('import_mesh', True) options.set_editor_property('import_textures', False) options.set_editor_property('import_materials', False) options.set_editor_property('import_as_skeletal', False) # Static Mesh options.static_mesh_import_data.set_editor_property( 'auto_generate_collision', False) # ---- Transform options.static_mesh_import_data.set_editor_property( 'import_translation', unreal.Vector(0.0, 0.0, 0.0)) options.static_mesh_import_data.set_editor_property( 'import_rotation', unreal.Rotator(0.0, 0.0, 0.0)) options.static_mesh_import_data.set_editor_property( 'import_uniform_scale', 1.0) # ---- Miscellaneous options.static_mesh_import_data.set_editor_property( 'convert_scene', True) options.static_mesh_import_data.set_editor_property( 'force_front_x_axis', False) options.static_mesh_import_data.set_editor_property( 'convert_scene_unit', True) options.set_editor_property('override_full_name', True) return options
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
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
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)
def fbx_import_option(self): options = unreal.FbxImportUI() options.auto_compute_lod_distances = False options.lod_number = 0 options.import_as_skeletal = bool(self.asset_data.get("skeletal_mesh")) options.import_animations = bool(self.asset_data.get("animation")) options.import_materials = bool(self.asset_data.get("import_materials")) options.import_textures = bool(self.asset_data.get("import_textures")) options.import_mesh = bool(self.asset_data.get("import_mesh")) options.static_mesh_import_data.generate_lightmap_u_vs = False options.lod_distance0 = 1.0 # if this is a skeletal mesh import if bool(self.asset_data.get("skeletal_mesh")): options.skeletal_mesh_import_data.normal_import_method = unreal.FBXNormalImportMethod.FBXNIM_IMPORT_NORMALS_AND_TANGENTS options.mesh_type_to_import = unreal.FBXImportType.FBXIT_SKELETAL_MESH options.skeletal_mesh_import_data.import_mesh_lo_ds = bool(self.asset_data.get("lods")) asset_name = self.asset_data.get("skeletal_mesh_game_path") if asset_name.find("/") != -1: unreal.log(unreal.EditorAssetLibrary.does_asset_exist(asset_name)) if unreal.EditorAssetLibrary.does_asset_exist(asset_name): asset = unreal.load_asset(asset_name) skeleton_asset_name = os.path.splitext(asset.get_editor_property("skeleton").get_path_name())[0] skeleton_asset = unreal.load_asset(skeleton_asset_name) unreal.log(skeleton_asset) if skeleton_asset: options.set_editor_property("skeleton", skeleton_asset) # if this is an static mesh import elif not bool(self.asset_data.get("skeletal_mesh")): options.static_mesh_import_data.normal_import_method = unreal.FBXNormalImportMethod.FBXNIM_IMPORT_NORMALS_AND_TANGENTS options.mesh_type_to_import = unreal.FBXImportType.FBXIT_STATIC_MESH options.static_mesh_import_data.import_mesh_lo_ds = bool(self.asset_data.get("lods")) # if this is an animation import if bool(self.asset_data.get("animation")): asset_name = self.asset_data.get("skeletal_mesh_game_path") if unreal.EditorAssetLibrary.does_asset_exist(asset_name): asset = unreal.load_asset(asset_name) skeleton_asset_name = os.path.splitext(asset.get_editor_property("skeleton").get_path_name())[0] skeleton_asset = unreal.load_asset(skeleton_asset_name) unreal.log(skeleton_asset) # if a skeleton can be loaded from the provided path if skeleton_asset: options.set_editor_property("skeleton", skeleton_asset) options.set_editor_property("original_import_type", unreal.FBXImportType.FBXIT_ANIMATION) options.set_editor_property("mesh_type_to_import", unreal.FBXImportType.FBXIT_ANIMATION) else: raise RuntimeError("Unreal could not find a skeleton here: {0}".format( self.asset_data.get("skeletal_mesh_game_path"))) return options
def buildAnimationImportOptions(skeleton_path=''): options = unreal.FbxImportUI() # unreal.FbxImportUI options.set_editor_property('import_animations', True) options.skeleton = unreal.load_asset(skeleton_path) # unreal.FbxMeshImportData options.anim_sequence_import_data.set_editor_property('import_translation', unreal.Vector(0.0, 0.0, 0.0)) options.anim_sequence_import_data.set_editor_property('import_rotation', unreal.Rotator(0.0, 0.0, 0.0)) options.anim_sequence_import_data.set_editor_property('import_uniform_scale', 1.0) # unreal.FbxAnimSequenceImportData options.anim_sequence_import_data.set_editor_property('animation_length', unreal.FBXAnimationLengthImportType.FBXALIT_EXPORTED_TIME) options.anim_sequence_import_data.set_editor_property('remove_redundant_keys', False) return options
def staticmesh_for_import_task_option(): options = unreal.FbxImportUI() options.import_mesh = True options.import_textures = False options.import_materials = False options.import_as_skeletal = False options.mesh_type_to_import = unreal.FBXImportType.FBXIT_STATIC_MESH nomral_method = unreal.FBXNormalImportMethod.FBXNIM_COMPUTE_NORMALS options.static_mesh_import_data.normal_import_method = nomral_method options.static_mesh_import_data.combine_meshes = False options.static_mesh_import_data.auto_generate_collision = False options.static_mesh_import_data.compute_weighted_normals = False return options
def _get_skeletal_mesh_import_options(): """Returns hard coded SkeletalMesh import options.""" options = unreal.FbxImportUI() options.import_as_skeletal = True options.mesh_type_to_import = unreal.FBXImportType.FBXIT_SKELETAL_MESH # Default to compute normals. import_method = unreal.FBXNormalImportMethod.FBXNIM_COMPUTE_NORMALS options.skeletal_mesh_import_data.normal_import_method = import_method # Don't import materials or textures. options.import_materials = False options.import_textures = False return options
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)
def buildSkeletalMeshImportOptions(): options = unreal.FbxImportUI() # unreal.FbxImportUI options.set_editor_property('import_mesh', True) options.set_editor_property('import_textures', False) options.set_editor_property('import_materials', False) options.set_editor_property('import_as_skeletal', True) # Skeletal Mesh # unreal.FbxMeshImportData options.skeletal_mesh_import_data.set_editor_property('import_translation', unreal.Vector(0.0, 0.0, 0.0)) options.skeletal_mesh_import_data.set_editor_property('import_rotation', unreal.Rotator(0.0, 0.0, 0.0)) options.skeletal_mesh_import_data.set_editor_property('import_uniform_scale', 1.0) # unreal.FbxSkeletalMeshImportData options.skeletal_mesh_import_data.set_editor_property('import_morph_targets', True) options.skeletal_mesh_import_data.set_editor_property('update_skeleton_reference_pose', False) return options
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'])
def buildStaticMeshImportOptions(): options = unreal.FbxImportUI() # unreal.FbxImportUI options.set_editor_property('import_mesh', True) options.set_editor_property('import_textures', False) options.set_editor_property('import_materials', False) options.set_editor_property('import_as_skeletal', False) # Static Mesh # unreal.FbxMeshImportData options.static_mesh_import_data.set_editor_property('import_translation', unreal.Vector(0.0, 0.0, 0.0)) options.static_mesh_import_data.set_editor_property('import_rotation', unreal.Rotator(0.0, 0.0, 0.0)) options.static_mesh_import_data.set_editor_property('import_uniform_scale', 1.0) # unreal.FbxStaticMeshImportData options.static_mesh_import_data.set_editor_property('combine_meshes', True) options.static_mesh_import_data.set_editor_property('generate_lightmap_u_vs', True) options.static_mesh_import_data.set_editor_property('auto_generate_collision', True) return options
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 build_import_options(): options = unreal.FbxImportUI() # ---- MESH options.set_editor_property('mesh_type_to_import', unreal.FBXImportType.FBXIT_SKELETAL_MESH) options.set_editor_property('import_mesh', True) options.set_editor_property('import_textures', False) options.set_editor_property('import_materials', False) options.set_editor_property('import_as_skeletal', True) # Static Mesh options.skeletal_mesh_import_data.set_editor_property( 'vertex_color_import_option', unreal.VertexColorImportOption.REPLACE) options.skeletal_mesh_import_data.set_editor_property( 'update_skeleton_reference_pose', True) options.skeletal_mesh_import_data.set_editor_property( 'use_t0_as_ref_pose', True) options.skeletal_mesh_import_data.set_editor_property( 'preserve_smoothing_groups', True) options.skeletal_mesh_import_data.set_editor_property( 'import_meshes_in_bone_hierarchy', True) options.skeletal_mesh_import_data.set_editor_property( 'import_morph_targets', False) options.skeletal_mesh_import_data.set_editor_property( 'import_mesh_lo_ds', False) options.skeletal_mesh_import_data.set_editor_property( 'normal_import_method', unreal.FBXNormalImportMethod.FBXNIM_IMPORT_NORMALS_AND_TANGENTS) # ---- Transform options.skeletal_mesh_import_data.set_editor_property( 'import_translation', unreal.Vector(0.0, 0.0, 0.0)) options.skeletal_mesh_import_data.set_editor_property( 'import_rotation', unreal.Rotator(0.0, 0.0, 0.0)) options.skeletal_mesh_import_data.set_editor_property( 'import_uniform_scale', 1.0) # ---- Miscellaneous options.skeletal_mesh_import_data.set_editor_property( 'convert_scene', True) options.skeletal_mesh_import_data.set_editor_property( 'force_front_x_axis', False) options.skeletal_mesh_import_data.set_editor_property( 'convert_scene_unit', True) options.set_editor_property('override_full_name', True) return options
def import_animation(skeleton, anim_source_path, anim_dest_path): # Animation section anim_seq_import_data = unreal.FbxAnimSequenceImportData() anim_seq_import_data.set_editor_property("animation_length", unreal.FBXAnimationLengthImportType.FBXALIT_EXPORTED_TIME) anim_seq_import_data.set_editor_property("convert_scene", True) anim_seq_import_data.set_editor_property("use_default_sample_rate", True) anim_seq_import_data.set_editor_property("import_bone_tracks", True) anim_seq_import_data.set_editor_property("import_meshes_in_bone_hierarchy", False) anim_seq_import_data.set_editor_property("import_custom_attribute", False) anim_seq_import_data.set_editor_property("do_not_import_curve_with_zero", False) anim_seq_import_data.set_editor_property("remove_redundant_keys", False) # FBX Import UI options ui_import_options = unreal.FbxImportUI() ui_import_options.reset_to_default() ui_import_options.set_editor_property("automated_import_should_detect_type", False) ui_import_options.set_editor_property("import_animations", True) ui_import_options.set_editor_property("import_as_skeletal", False) ui_import_options.set_editor_property("import_rigid_mesh", False) ui_import_options.set_editor_property("import_materials", False) ui_import_options.set_editor_property("import_mesh", False) ui_import_options.set_editor_property("import_textures", False) ui_import_options.set_editor_property("mesh_type_to_import", unreal.FBXImportType.FBXIT_ANIMATION) ui_import_options.set_editor_property("skeleton", skeleton) ui_import_options.set_editor_property("anim_sequence_import_data",anim_seq_import_data) # Create Import task asset_import_task = unreal.AssetImportTask() asset_import_task.set_editor_property("automated", True) asset_import_task.set_editor_property("destination_path",anim_dest_path) asset_import_task.set_editor_property("filename",anim_source_path) asset_import_task.set_editor_property("options",ui_import_options) asset_import_task.set_editor_property("save", True) tasks = [asset_import_task] # Run import task asset_tools = unreal.AssetToolsHelpers.get_asset_tools() #asset_tools.import_asset_tasks(tasks) unreal.AssetTools.import_asset_tasks(asset_tools, tasks)
def buildSkeletalMeshImportOptions(self): skeletal_mesh_import_data = unreal.FbxSkeletalMeshImportData() skeletal_mesh_import_data.set_editor_property( 'update_skeleton_reference_pose', False) skeletal_mesh_import_data.set_editor_property( 'import_meshes_in_bone_hierarchy', True) skeletal_mesh_import_data.set_editor_property('use_t0_as_ref_pose', False) skeletal_mesh_import_data.set_editor_property( 'preserve_smoothing_groups', True) skeletal_mesh_import_data.set_editor_property('import_morph_targets', True) import_translation = unreal.Vector(0, 0, 0) skeletal_mesh_import_data.set_editor_property('import_translation', import_translation) import_rotation = unreal.Rotator(0, 0, 0) skeletal_mesh_import_data.set_editor_property('import_rotation', import_rotation) skeletal_mesh_import_data.set_editor_property('import_uniform_scale', 1.0) skeletal_mesh_import_data.set_editor_property('convert_scene', True) skeletal_mesh_import_data.set_editor_property('force_front_x_axis', False) skeletal_mesh_import_data.set_editor_property('convert_scene_unit', False) # SkeletalMeshImportData->bImportAsScene = false; options = unreal.FbxImportUI() options.set_editor_property('skeletal_mesh_import_data', skeletal_mesh_import_data) options.set_editor_property('import_mesh', True) options.set_editor_property('import_textures', False) options.set_editor_property('import_materials', False) options.set_editor_property('import_as_skeletal', True) options.set_editor_property('skeleton', None) # options.skeletal_mesh_import_data.set_edtitor_property('import_translation') # options.skeletal_mesh_import_data.set_edtitor_property('import_rotation') # options.skeletal_mesh_import_data.set_edtitor_property('import_uniform_scale') # options.skeletal_mesh_import_data.set_edtitor_property('combine_meshes',False) # options.skeletal_mesh_import_data.set_edtitor_property('generate_lightmap_u_v') # options.skeletal_mesh_import_data.set_edtitor_property('generate_lightmap') return options
def build_static_mesh_import_options(): options = unreal.FbxImportUI() # unreal.FbxImportUI https://api.unrealengine.com/INT/PythonAPI/class/FbxImportUI.html options.set_editor_property('import_mesh', True) options.set_editor_property('import_textures', False) options.set_editor_property('import_materials', False) options.set_editor_property('import_as_skeletal', False) # Static Mesh # unreal.FbxMeshImportData https://api.unrealengine.com/INT/PythonAPI/class/FbxMeshImportData.html options.static_mesh_import_data.set_editor_property( 'import_translation', unreal.Vector(0.0, 0.0, 0.0)) options.static_mesh_import_data.set_editor_property( 'import_rotation', unreal.Rotator(0.0, 0.0, 0.0)) options.static_mesh_import_data.set_editor_property( 'import_uniform_scale', 1.0) # unreal.FbxStaticMeshImportData https://api.unrealengine.com/INT/PythonAPI/class/FbxStaticMeshImportData.html options.static_mesh_import_data.set_editor_property('combine_meshes', True) options.static_mesh_import_data.set_editor_property( 'generate_lightmap_u_vs', True) options.static_mesh_import_data.set_editor_property( 'auto_generate_collision', True) return options
def build_skeletal_mesh_import_options(): options = unreal.FbxImportUI() # unreal.FbxImportUI https://api.unrealengine.com/INT/PythonAPI/class/FbxImportUI.html options.set_editor_property('import_mesh', True) options.set_editor_property('import_textures', True) options.set_editor_property('import_materials', True) options.set_editor_property('import_as_skeletal', True) # Skeletal Mesh # unreal.FbxMeshImportData https://api.unrealengine.com/INT/PythonAPI/class/FbxMeshImportData.html options.skeletal_mesh_import_data.set_editor_property( 'import_translation', unreal.Vector(0.0, 0.0, 0.0)) options.skeletal_mesh_import_data.set_editor_property( 'import_rotation', unreal.Rotator(0.0, 0.0, 0.0)) options.skeletal_mesh_import_data.set_editor_property( 'import_uniform_scale', 1.0) # unreal.FbxSkeletalMeshImportData # https://api.unrealengine.com/INT/PythonAPI/class/FbxSkeletalMeshImportData.html options.skeletal_mesh_import_data.set_editor_property( 'import_morph_targets', True) options.skeletal_mesh_import_data.set_editor_property( 'update_skeleton_reference_pose', False) return options
def buildStaticMeshImportOptions(self, bCombine_meshs=False): options = unreal.FbxImportUI() static_mesh_import_data = unreal.FbxStaticMeshImportData() static_mesh_import_data.set_editor_property('combine_meshes', False) if bCombine_meshs: static_mesh_import_data.set_editor_property('combine_meshes', True) options.set_editor_property('import_mesh', True) options.set_editor_property('import_textures', False) options.set_editor_property('import_materials', False) options.set_editor_property('import_as_skeletal', False) # options.static_mesh_import_data.set_edtitor_property('import_translation') # options.static_mesh_import_data.set_edtitor_property('import_rotation') # options.static_mesh_import_data.set_edtitor_property('import_uniform_scale') options.set_editor_property('static_mesh_import_data', static_mesh_import_data) # options.static_mesh_import_data.set_edtitor_property('generate_lightmap_u_v') # options.static_mesh_import_data.set_edtitor_property('generate_lightmap') return options
def update(self, container, representation): name = container["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) # 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', True) # set import options here options = unreal.FbxImportUI() options.set_editor_property('automated_import_should_detect_type', False) options.set_editor_property('import_animations', False) task.options = options # 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)
asset_path = '/Game/Slicer' unreal.EditorAssetLibrary.make_directory(asset_path) #now we make an import task and access it's options, which are similar to the import UI task = unreal.AssetImportTask() #now let's set some import options on the task class task.filename = baseurl + 'Slicer/slicer.fbx' task.destination_path = asset_path task.destination_name = 'slicer_run' task.replace_existing = True task.automated = True #save the file when it is imported, that's right! task.save = True task.options = unreal.FbxImportUI() task.options.import_as_skeletal = True task.options.override_full_name = True task.options.mesh_type_to_import = unreal.FBXImportType.FBXIT_SKELETAL_MESH task.options.skeletal_mesh_import_data.set_editor_property( 'update_skeleton_reference_pose', False) task.options.skeletal_mesh_import_data.set_editor_property( 'use_t0_as_ref_pose', True) task.options.skeletal_mesh_import_data.set_editor_property( 'preserve_smoothing_groups', 1) task.options.skeletal_mesh_import_data.set_editor_property( 'import_meshes_in_bone_hierarchy', False) task.options.skeletal_mesh_import_data.set_editor_property( 'import_morph_targets', True) task.options.skeletal_mesh_import_data.set_editor_property(
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 """ # Create directory for asset and avalon container root = "/Game/Avalon/Assets" asset = context.get('asset').get('name') suffix = "_CON" if asset: asset_name = "{}_{}".format(asset, name) else: asset_name = "{}".format(name) tools = unreal.AssetToolsHelpers().get_asset_tools() asset_dir, container_name = tools.create_unique_asset_name( "{}/{}/{}".format(root, asset, name), suffix="") container_name += suffix unreal.EditorAssetLibrary.make_directory(asset_dir) task = unreal.AssetImportTask() task.set_editor_property('filename', self.fname) task.set_editor_property('destination_path', asset_dir) task.set_editor_property('destination_name', asset_name) task.set_editor_property('replace_existing', False) task.set_editor_property('automated', True) task.set_editor_property('save', False) # 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 unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks( [task]) # noqa: E501 # Create Asset Container lib.create_avalon_container(container=container_name, path=asset_dir) data = { "schema": "openpype:container-2.0", "id": pipeline.AVALON_CONTAINER_ID, "asset": asset, "namespace": asset_dir, "container_name": container_name, "asset_name": asset_name, "loader": str(self.__class__.__name__), "representation": context["representation"]["_id"], "parent": context["representation"]["parent"], "family": context["representation"]["context"]["family"] } unreal_pipeline.imprint("{}/{}".format(asset_dir, container_name), data) asset_content = unreal.EditorAssetLibrary.list_assets( asset_dir, recursive=True, include_folder=True) for a in asset_content: unreal.EditorAssetLibrary.save_asset(a) return asset_content
def ImportTask(): # New import task # Property if asset_data["type"] == "Animation": find_asset = unreal.find_asset( asset_data["animation_skeleton_path"]) if isinstance(find_asset, unreal.Skeleton): OriginSkeleton = find_asset elif isinstance(find_asset, unreal.SkeletalMesh): OriginSkeleton = find_asset.skeleton else: OriginSkeleton = None task = unreal.AssetImportTask() if asset_data["type"] == "Alembic": task.filename = asset_data["abc_path"] else: task.filename = asset_data["fbx_path"] task.destination_path = os.path.normpath( asset_data["full_import_path"]).replace('\\', '/') task.automated = True task.save = True task.replace_existing = True if asset_data["type"] == "Alembic": task.set_editor_property('options', unreal.AbcImportSettings()) else: task.set_editor_property('options', unreal.FbxImportUI()) # #################################[Change] # unreal.FbxImportUI # https://docs.unrealengine.com/en-US/PythonAPI/class/FbxImportUI.html?highlight=fbximportui#unreal.FbxImportUI if asset_data["type"] == "Alembic": task.get_editor_property('options').set_editor_property( 'import_type', unreal.AlembicImportType.SKELETAL) else: if asset_data["type"] == "Animation": if OriginSkeleton: task.get_editor_property( 'options').set_editor_property( 'Skeleton', OriginSkeleton) else: ImportFailList.append( 'Skeleton ' + asset_data["animation_skeleton_path"] + ' Not found for ' + asset_data["name"] + ' asset.') return if asset_data["type"] == "StaticMesh": task.get_editor_property('options').set_editor_property( 'original_import_type', unreal.FBXImportType.FBXIT_STATIC_MESH) elif asset_data["type"] == "Animation": task.get_editor_property('options').set_editor_property( 'original_import_type', unreal.FBXImportType.FBXIT_ANIMATION) else: task.get_editor_property('options').set_editor_property( 'original_import_type', unreal.FBXImportType.FBXIT_SKELETAL_MESH) if asset_data["type"] == "Animation": task.get_editor_property('options').set_editor_property( 'import_materials', False) else: task.get_editor_property('options').set_editor_property( 'import_materials', True) task.get_editor_property('options').set_editor_property( 'import_textures', False) if asset_data["type"] == "Animation": task.get_editor_property('options').set_editor_property( 'import_animations', True) task.get_editor_property('options').set_editor_property( 'import_mesh', False) task.get_editor_property('options').set_editor_property( 'create_physics_asset', False) else: task.get_editor_property('options').set_editor_property( 'import_animations', False) task.get_editor_property('options').set_editor_property( 'import_mesh', True) if "create_physics_asset" in asset_data: task.get_editor_property( 'options').set_editor_property( 'create_physics_asset', asset_data["create_physics_asset"]) # unreal.FbxMeshImportData if asset_data["type"] == "StaticMesh" or asset_data[ "type"] == "SkeletalMesh": if "material_search_location" in asset_data: # unreal.FbxTextureImportData if asset_data["material_search_location"] == "Local": task.get_editor_property( 'options' ).texture_import_data.set_editor_property( 'material_search_location', unreal.MaterialSearchLocation.LOCAL) if asset_data[ "material_search_location"] == "UnderParent": task.get_editor_property( 'options' ).texture_import_data.set_editor_property( 'material_search_location', unreal.MaterialSearchLocation.UNDER_PARENT) if asset_data[ "material_search_location"] == "UnderRoot": task.get_editor_property( 'options' ).texture_import_data.set_editor_property( 'material_search_location', unreal.MaterialSearchLocation.UNDER_ROOT) if asset_data[ "material_search_location"] == "AllAssets": task.get_editor_property( 'options' ).texture_import_data.set_editor_property( 'material_search_location', unreal.MaterialSearchLocation.ALL_ASSETS) if asset_data["type"] == "StaticMesh": # unreal.FbxStaticMeshImportData task.get_editor_property( 'options').static_mesh_import_data.set_editor_property( 'combine_meshes', True) if "auto_generate_collision" in asset_data: task.get_editor_property( 'options' ).static_mesh_import_data.set_editor_property( 'auto_generate_collision', asset_data["auto_generate_collision"]) if "static_mesh_lod_group" in asset_data: if asset_data["static_mesh_lod_group"]: task.get_editor_property( 'options' ).static_mesh_import_data.set_editor_property( 'static_mesh_lod_group', asset_data["static_mesh_lod_group"]) if "generate_lightmap_u_vs" in asset_data: task.get_editor_property( 'options' ).static_mesh_import_data.set_editor_property( 'generate_lightmap_u_vs', asset_data["generate_lightmap_u_vs"]) if asset_data["type"] == "StaticMesh" or asset_data[ "type"] == "SkeletalMesh": vertex_color_import_option = unreal.VertexColorImportOption.REPLACE # Default if "vertex_override_color" in asset_data: vertex_override_color = unreal.LinearColor( asset_data["vertex_override_color"][0], asset_data["vertex_override_color"][1], asset_data["vertex_override_color"][2]) if "vertex_color_import_option" in asset_data: if asset_data[ "vertex_color_import_option"] == "IGNORE": vertex_color_import_option = unreal.VertexColorImportOption.IGNORE elif asset_data[ "vertex_color_import_option"] == "OVERRIDE": vertex_color_import_option = unreal.VertexColorImportOption.OVERRIDE elif asset_data[ "vertex_color_import_option"] == "REPLACE": vertex_color_import_option = unreal.VertexColorImportOption.REPLACE if asset_data["type"] == "StaticMesh": # unreal.FbxSkeletalMeshImportData if "vertex_color_import_option" in asset_data: task.get_editor_property( 'options' ).static_mesh_import_data.set_editor_property( 'vertex_color_import_option', vertex_color_import_option) if "vertex_override_color" in asset_data: task.get_editor_property( 'options' ).static_mesh_import_data.set_editor_property( 'vertex_override_color', vertex_override_color.to_rgbe()) if asset_data["type"] == "SkeletalMesh": # unreal.FbxSkeletalMeshImportData if "vertex_color_import_option" in asset_data: task.get_editor_property( 'options' ).skeletal_mesh_import_data.set_editor_property( 'vertex_color_import_option', vertex_color_import_option) if "vertex_override_color" in asset_data: task.get_editor_property( 'options' ).skeletal_mesh_import_data.set_editor_property( 'vertex_override_color', vertex_override_color.to_rgbe()) if asset_data["type"] == "SkeletalMesh" or asset_data[ "type"] == "Animation": # unreal.FbxSkeletalMeshImportData 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) task.get_editor_property( 'options' ).skeletal_mesh_import_data.set_editor_property( 'normal_import_method', unreal.FBXNormalImportMethod. FBXNIM_IMPORT_NORMALS_AND_TANGENTS) # ###############[ import asset ]################ print("Import task") if asset_data["type"] == "Animation": ''' For animation the script will import a skeletal mesh and remove after. If the skeletal mesh alredy exist try to remove. ''' # task.destination_name = "TempAnimationImportName" # unreal.EditorAssetLibrary.delete_asset("SkeletalMesh'"+asset_data["full_import_path"]+"/TempAnimationImportName.TempAnimationImportName'") unreal.EditorAssetLibrary.delete_asset( "SkeletalMesh'" + asset_data["full_import_path"] + "/" + asset_data["name"] + "." + asset_data["name"] + "'") print( 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 is None: ImportFailList.append('Error zero imported object for: ' + asset_data["name"]) return if asset_data["type"] == "Animation": # For animation remove the extra mesh p = task.imported_object_paths[0] if type(unreal.find_asset(p)) is not unreal.AnimSequence: animAssetName = p.split('.')[0] + '_anim.' + p.split( '.')[1] + '_anim' animAssetNameDesiredPath = p.split('.')[0] + '.' + p.split( '.')[1] animAsset = unreal.find_asset(animAssetName) if animAsset is not None: unreal.EditorAssetLibrary.delete_asset(p) unreal.EditorAssetLibrary.rename_asset( animAssetName, animAssetNameDesiredPath) asset = animAsset else: ImportFailList.append('animAsset ' + asset_data["name"] + ' not found for after inport: ' + animAssetName) return # ###############[ Post treatment ]################ if asset_data["type"] == "StaticMesh": if "static_mesh_lod_group" in asset_data: if asset_data["static_mesh_lod_group"]: asset.set_editor_property( 'lod_group', asset_data["static_mesh_lod_group"]) if "light_map_resolution" in asset_data: asset.set_editor_property( 'light_map_resolution', asset_data["light_map_resolution"]) if "collision_trace_flag" in asset_data: if asset_data["collision_trace_flag"] == "CTF_UseDefault": asset.get_editor_property( 'body_setup').set_editor_property( 'collision_trace_flag', unreal.CollisionTraceFlag.CTF_USE_DEFAULT) elif asset_data[ "collision_trace_flag"] == "CTF_UseSimpleAndComplex": asset.get_editor_property( 'body_setup').set_editor_property( 'collision_trace_flag', unreal. CollisionTraceFlag.CTF_USE_SIMPLE_AND_COMPLEX) elif asset_data[ "collision_trace_flag"] == "CTF_UseSimpleAsComplex": asset.get_editor_property( 'body_setup').set_editor_property( 'collision_trace_flag', unreal. CollisionTraceFlag.CTF_USE_SIMPLE_AS_COMPLEX) elif asset_data[ "collision_trace_flag"] == "CTF_UseComplexAsSimple": asset.get_editor_property( 'body_setup').set_editor_property( 'collision_trace_flag', unreal. CollisionTraceFlag.CTF_USE_COMPLEX_AS_SIMPLE) if asset_data["type"] == "StaticMesh" or asset_data[ "type"] == "SkeletalMesh": vertex_color_import_option = unreal.VertexColorImportOption.REPLACE # Default if "vertex_override_color" in asset_data: vertex_override_color = unreal.LinearColor( asset_data["vertex_override_color"][0], asset_data["vertex_override_color"][1], asset_data["vertex_override_color"][2]) if "vertex_color_import_option" in asset_data: if asset_data["vertex_color_import_option"] == "IGNORE": vertex_color_import_option = unreal.VertexColorImportOption.IGNORE elif asset_data[ "vertex_color_import_option"] == "OVERRIDE": vertex_color_import_option = unreal.VertexColorImportOption.OVERRIDE elif asset_data["vertex_color_import_option"] == "REPLACE": vertex_color_import_option = unreal.VertexColorImportOption.REPLACE if "vertex_color_import_option" in asset_data: asset.get_editor_property( 'asset_import_data').set_editor_property( 'vertex_color_import_option', vertex_color_import_option) if "vertex_override_color" in asset_data: asset.get_editor_property( 'asset_import_data').set_editor_property( 'vertex_override_color', vertex_override_color.to_rgbe()) if asset_data["type"] == "StaticMesh": if "generate_lightmap_u_vs" in asset_data: asset.get_editor_property( 'asset_import_data').set_editor_property( 'generate_lightmap_u_vs', asset_data["generate_lightmap_u_vs"] ) # Import data unreal.EditorStaticMeshLibrary.set_generate_lightmap_uv( asset, asset_data["generate_lightmap_u_vs"] ) # Build settings at lod if asset_data["type"] == "SkeletalMesh": asset.get_editor_property( 'asset_import_data').set_editor_property( 'normal_import_method', unreal.FBXNormalImportMethod. FBXNIM_IMPORT_NORMALS_AND_TANGENTS) # with open(asset_data["additional_tracks_path"], "r") as json_file: # asset_tracks = json.load(json_file) # Socket if asset_data["type"] == "SkeletalMesh": # Import the SkeletalMesh socket(s) sockets_to_add = GetOptionByIniFile( asset_data["additional_tracks_path"], 'Sockets', True) skeleton = asset.get_editor_property('skeleton') for socket in sockets_to_add: pass # Create socket # new_socket = unreal.SkeletalMeshSocket('', skeleton) # new_socket.SocketName = socket[0] # Lod if asset_data["type"] == "StaticMesh" or asset_data[ "type"] == "SkeletalMesh": if asset_data["type"] == "StaticMesh": unreal.EditorStaticMeshLibrary.remove_lods( asset) # Import the StaticMesh lod(s) if asset_data["type"] == "SkeletalMesh" or asset_data[ "type"] == "StaticMesh": lods_to_add = GetOptionByIniFile( asset_data["additional_tracks_path"], 'LevelOfDetail') # Import the SkeletalMesh lod(s) for x, lod in enumerate(lods_to_add): if asset_data["type"] == "StaticMesh": lodTask = unreal.AssetImportTask() lodTask.filename = lod lodTask.destination_path = os.path.normpath( asset_data["full_import_path"]).replace( '\\', '/') lodTask.automated = True lodTask.replace_existing = True unreal.AssetToolsHelpers.get_asset_tools( ).import_asset_tasks([lodTask]) lodAsset = unreal.find_asset( lodTask.imported_object_paths[0]) slot_replaced = unreal.EditorStaticMeshLibrary.set_lod_from_static_mesh( asset, x + 1, lodAsset, 0, True) unreal.EditorAssetLibrary.delete_asset( lodTask.imported_object_paths[0]) elif asset_data["type"] == "SkeletalMesh": pass unreal.FbxMeshUtils.ImportSkeletalMeshLOD( asset, lod, x + 1 ) # Vania unreal python dont have unreal.FbxMeshUtils. # #################################[EndChange] if asset_data["type"] == "StaticMesh" or asset_data[ "type"] == "SkeletalMesh": unreal.EditorAssetLibrary.save_loaded_asset(asset) ImportedList.append([asset, asset_data["type"]])
def ImportTask(): # New import task # Property if asset_data["type"] == "Animation": find_asset = unreal.find_asset( asset_data["animation_skeleton_path"]) if isinstance(find_asset, unreal.Skeleton): OriginSkeleton = find_asset elif isinstance(find_asset, unreal.SkeletalMesh): OriginSkeleton = find_asset.skeleton else: OriginSkeleton = None # docs.unrealengine.com/4.26/en-US/PythonAPI/class/AssetImportTask.html task = unreal.AssetImportTask() def GetStaticMeshImportData(): if asset_data["type"] == "StaticMesh": return task.get_editor_property( 'options').static_mesh_import_data return None def GetSkeletalMeshImportData(): if asset_data["type"] == "SkeletalMesh": return task.get_editor_property( 'options').skeletal_mesh_import_data return None def GetAnimationImportData(): if asset_data["type"] == "Animation": return task.get_editor_property( 'options').anim_sequence_import_data return None def GetAlembicImportData(): if asset_data["type"] == "Alembic": return task.get_editor_property('options') return None def GetMeshImportData(): if asset_data["type"] == "StaticMesh": return GetStaticMeshImportData() if asset_data["type"] == "SkeletalMesh": return GetSkeletalMeshImportData() return None if asset_data["type"] == "Alembic": task.filename = asset_data["abc_path"] else: task.filename = asset_data["fbx_path"] task.destination_path = os.path.normpath( asset_data["full_import_path"]).replace('\\', '/') task.automated = True # task.automated = False #Debug for show dialog task.save = True task.replace_existing = True if asset_data["type"] == "Alembic": task.set_editor_property('options', unreal.AbcImportSettings()) else: task.set_editor_property('options', unreal.FbxImportUI()) # Alembic if GetAlembicImportData(): GetAlembicImportData( ).static_mesh_settings.set_editor_property( "merge_meshes", True) GetAlembicImportData().set_editor_property( "import_type", unreal.AlembicImportType.SKELETAL) GetAlembicImportData().conversion_settings.set_editor_property( "flip_u", False) GetAlembicImportData().conversion_settings.set_editor_property( "flip_v", True) GetAlembicImportData().conversion_settings.set_editor_property( "scale", unreal.Vector(100, -100, 100)) GetAlembicImportData().conversion_settings.set_editor_property( "rotation", unreal.Vector(90, 0, 0)) # Vertex color vertex_override_color = None vertex_color_import_option = None if additional_data: if "vertex_color_import_option" in additional_data: if additional_data[ "vertex_color_import_option"] == "IGNORE": vertex_color_import_option = unreal.VertexColorImportOption.IGNORE elif additional_data[ "vertex_color_import_option"] == "OVERRIDE": vertex_color_import_option = unreal.VertexColorImportOption.OVERRIDE elif additional_data[ "vertex_color_import_option"] == "REPLACE": vertex_color_import_option = unreal.VertexColorImportOption.REPLACE vertex_color_import_option = unreal.VertexColorImportOption.REPLACE # Default if "vertex_override_color" in additional_data: vertex_override_color = unreal.LinearColor( additional_data["vertex_override_color"][0], additional_data["vertex_override_color"][1], additional_data["vertex_override_color"][2]) # #################################[Change] # unreal.FbxImportUI # https://docs.unrealengine.com/4.26/en-US/PythonAPI/class/FbxImportUI.html # Import transform anim_sequence_import_data = GetAnimationImportData() if anim_sequence_import_data: anim_sequence_import_data.import_translation = unreal.Vector( 0, 0, 0) # Vertex color if vertex_color_import_option and GetMeshImportData(): GetMeshImportData().set_editor_property( 'vertex_color_import_option', vertex_color_import_option) if vertex_override_color and GetMeshImportData(): GetMeshImportData().set_editor_property( 'vertex_override_color', vertex_override_color.to_rgbe()) if asset_data["type"] == "Alembic": task.get_editor_property('options').set_editor_property( 'import_type', unreal.AlembicImportType.SKELETAL) else: if asset_data["type"] == "Animation": if OriginSkeleton: task.get_editor_property( 'options').set_editor_property( 'Skeleton', OriginSkeleton) else: ImportFailList.append( 'Skeleton ' + asset_data["animation_skeleton_path"] + ' Not found for ' + asset_data["name"] + ' asset.') return if asset_data["type"] == "StaticMesh": task.get_editor_property('options').set_editor_property( 'original_import_type', unreal.FBXImportType.FBXIT_STATIC_MESH) elif asset_data["type"] == "Animation": task.get_editor_property('options').set_editor_property( 'original_import_type', unreal.FBXImportType.FBXIT_ANIMATION) else: task.get_editor_property('options').set_editor_property( 'original_import_type', unreal.FBXImportType.FBXIT_SKELETAL_MESH) if asset_data["type"] == "Animation": task.get_editor_property('options').set_editor_property( 'import_materials', False) else: task.get_editor_property('options').set_editor_property( 'import_materials', True) task.get_editor_property('options').set_editor_property( 'import_textures', False) if asset_data["type"] == "Animation": task.get_editor_property('options').set_editor_property( 'import_animations', True) task.get_editor_property('options').set_editor_property( 'import_mesh', False) task.get_editor_property('options').set_editor_property( 'create_physics_asset', False) else: task.get_editor_property('options').set_editor_property( 'import_animations', False) task.get_editor_property('options').set_editor_property( 'import_mesh', True) if "create_physics_asset" in asset_data: task.get_editor_property( 'options').set_editor_property( 'create_physics_asset', asset_data["create_physics_asset"]) # unreal.FbxMeshImportData if asset_data["type"] == "StaticMesh" or asset_data[ "type"] == "SkeletalMesh": if "material_search_location" in asset_data: # unreal.FbxTextureImportData if asset_data["material_search_location"] == "Local": task.get_editor_property( 'options' ).texture_import_data.set_editor_property( 'material_search_location', unreal.MaterialSearchLocation.LOCAL) if asset_data[ "material_search_location"] == "UnderParent": task.get_editor_property( 'options' ).texture_import_data.set_editor_property( 'material_search_location', unreal.MaterialSearchLocation.UNDER_PARENT) if asset_data[ "material_search_location"] == "UnderRoot": task.get_editor_property( 'options' ).texture_import_data.set_editor_property( 'material_search_location', unreal.MaterialSearchLocation.UNDER_ROOT) if asset_data[ "material_search_location"] == "AllAssets": task.get_editor_property( 'options' ).texture_import_data.set_editor_property( 'material_search_location', unreal.MaterialSearchLocation.ALL_ASSETS) if asset_data["type"] == "StaticMesh": # unreal.FbxStaticMeshImportData task.get_editor_property( 'options').static_mesh_import_data.set_editor_property( 'combine_meshes', True) if "auto_generate_collision" in asset_data: task.get_editor_property( 'options' ).static_mesh_import_data.set_editor_property( 'auto_generate_collision', asset_data["auto_generate_collision"]) if "static_mesh_lod_group" in asset_data: if asset_data["static_mesh_lod_group"]: task.get_editor_property( 'options' ).static_mesh_import_data.set_editor_property( 'static_mesh_lod_group', asset_data["static_mesh_lod_group"]) if "generate_lightmap_u_vs" in asset_data: task.get_editor_property( 'options' ).static_mesh_import_data.set_editor_property( 'generate_lightmap_u_vs', asset_data["generate_lightmap_u_vs"]) if asset_data["type"] == "SkeletalMesh" or asset_data[ "type"] == "Animation": # unreal.FbxSkeletalMeshImportData 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) task.get_editor_property( 'options' ).skeletal_mesh_import_data.set_editor_property( 'normal_import_method', unreal.FBXNormalImportMethod. FBXNIM_IMPORT_NORMALS_AND_TANGENTS) # ###############[ pre import ]################ # Check is the file alredy exit if additional_data: if "preview_import_path" in additional_data: task_asset_full_path = task.destination_path + "/" + additional_data[ "preview_import_path"] + "." + additional_data[ "preview_import_path"] find_asset = unreal.find_asset(task_asset_full_path) if find_asset: # Vertex color asset_import_data = find_asset.get_editor_property( 'asset_import_data') if vertex_color_import_option: asset_import_data.set_editor_property( 'vertex_color_import_option', vertex_color_import_option) if vertex_override_color: asset_import_data.set_editor_property( 'vertex_override_color', vertex_override_color.to_rgbe()) # ###############[ import asset ]################ print("Import task") if asset_data["type"] == "Animation": ''' For animation the script will import a skeletal mesh and remove after. If the skeletal mesh alredy exist try to remove. ''' AssetName = asset_data["name"] AssetName = ValidUnrealAssetsName(AssetName) AssetPath = "SkeletalMesh'" + asset_data[ "full_import_path"] + "/" + AssetName + "." + AssetName + "'" if unreal.EditorAssetLibrary.does_asset_exist(AssetPath): oldAsset = unreal.EditorAssetLibrary.find_asset_data( AssetPath) if oldAsset.asset_class == "SkeletalMesh": unreal.EditorAssetLibrary.delete_asset(AssetPath) 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 is None: ImportFailList.append('Error zero imported object for: ' + asset_data["name"]) return if asset_data["type"] == "Animation": # For animation remove the extra mesh p = task.imported_object_paths[0] if type(unreal.find_asset(p)) is not unreal.AnimSequence: animAssetName = p.split('.')[0] + '_anim.' + p.split( '.')[1] + '_anim' animAssetNameDesiredPath = p.split('.')[0] + '.' + p.split( '.')[1] animAsset = unreal.find_asset(animAssetName) if animAsset is not None: unreal.EditorAssetLibrary.delete_asset(p) unreal.EditorAssetLibrary.rename_asset( animAssetName, animAssetNameDesiredPath) asset = animAsset else: ImportFailList.append('animAsset ' + asset_data["name"] + ' not found for after inport: ' + animAssetName) return # ###############[ Post treatment ]################ asset_import_data = asset.get_editor_property('asset_import_data') if asset_data["type"] == "StaticMesh": if "static_mesh_lod_group" in asset_data: if asset_data["static_mesh_lod_group"]: asset.set_editor_property( 'lod_group', asset_data["static_mesh_lod_group"]) if "use_custom_light_map_resolution" in asset_data: if asset_data["use_custom_light_map_resolution"]: if "light_map_resolution" in asset_data: asset.set_editor_property( 'light_map_resolution', asset_data["light_map_resolution"]) if "collision_trace_flag" in asset_data: if asset_data["collision_trace_flag"] == "CTF_UseDefault": asset.get_editor_property( 'body_setup').set_editor_property( 'collision_trace_flag', unreal.CollisionTraceFlag.CTF_USE_DEFAULT) elif asset_data[ "collision_trace_flag"] == "CTF_UseSimpleAndComplex": asset.get_editor_property( 'body_setup').set_editor_property( 'collision_trace_flag', unreal. CollisionTraceFlag.CTF_USE_SIMPLE_AND_COMPLEX) elif asset_data[ "collision_trace_flag"] == "CTF_UseSimpleAsComplex": asset.get_editor_property( 'body_setup').set_editor_property( 'collision_trace_flag', unreal. CollisionTraceFlag.CTF_USE_SIMPLE_AS_COMPLEX) elif asset_data[ "collision_trace_flag"] == "CTF_UseComplexAsSimple": asset.get_editor_property( 'body_setup').set_editor_property( 'collision_trace_flag', unreal. CollisionTraceFlag.CTF_USE_COMPLEX_AS_SIMPLE) if asset_data["type"] == "StaticMesh": if "generate_lightmap_u_vs" in asset_data: asset_import_data.set_editor_property( 'generate_lightmap_u_vs', asset_data["generate_lightmap_u_vs"]) # Import data unreal.EditorStaticMeshLibrary.set_generate_lightmap_uv( asset, asset_data["generate_lightmap_u_vs"] ) # Build settings at lod if asset_data["type"] == "SkeletalMesh": asset_import_data.set_editor_property( 'normal_import_method', unreal.FBXNormalImportMethod. FBXNIM_IMPORT_NORMALS_AND_TANGENTS) # Socket if asset_data["type"] == "SkeletalMesh": # Import the SkeletalMesh socket(s) sockets_to_add = additional_data["Sockets"] skeleton = asset.get_editor_property('skeleton') for socket in sockets_to_add: old_socket = asset.find_socket(socket["SocketName"]) if old_socket: # Edit socket pass # old_socket.relative_location = socket["Location"] # old_socket.relative_rotation = socket["Rotation"] # old_socket.relative_scale = socket["Scale"] else: # Create socket pass # new_socket = unreal.SkeletalMeshSocket(asset) # new_socket.socket_name = socket["SocketName"] # new_socket.bone_name = socket["BoneName"] # new_socket.relative_location = socket["Location"] # new_socket.relative_rotation = socket["Rotation"] # new_socket.relative_scale = socket["Scale"] # NEED UNREAL ENGINE IMPLEMENTATION IN PYTHON API. # skeleton.add_socket(new_socket) # Lod if asset_data["type"] == "StaticMesh" or asset_data[ "type"] == "SkeletalMesh": if asset_data["type"] == "StaticMesh": unreal.EditorStaticMeshLibrary.remove_lods( asset) # Import the StaticMesh lod(s) if asset_data["type"] == "SkeletalMesh" or asset_data[ "type"] == "StaticMesh": def ImportStaticLod(lod_name, lod_number): if "LevelOfDetail" in additional_data: if lod_name in additional_data["LevelOfDetail"]: lodTask = unreal.AssetImportTask() lodTask.filename = additional_data[ "LevelOfDetail"][lod_name] destination_path = os.path.normpath( asset_data["full_import_path"]).replace( '\\', '/') lodTask.destination_path = destination_path lodTask.automated = True lodTask.replace_existing = True print( destination_path, additional_data["LevelOfDetail"][lod_name]) unreal.AssetToolsHelpers.get_asset_tools( ).import_asset_tasks([lodTask]) if len(lodTask.imported_object_paths) > 0: lodAsset = unreal.find_asset( lodTask.imported_object_paths[0]) slot_replaced = unreal.EditorStaticMeshLibrary.set_lod_from_static_mesh( asset, lod_number, lodAsset, 0, True) unreal.EditorAssetLibrary.delete_asset( lodTask.imported_object_paths[0]) def ImportSkeletalLod(lod_name, lod_number): if "LevelOfDetail" in additional_data: if lod_name in additional_data["LevelOfDetail"]: # Unreal python no longer support Skeletal mesh LODS import. pass if asset_data["type"] == "StaticMesh": ImportStaticLod("lod_1", 1) ImportStaticLod("lod_2", 2) ImportStaticLod("lod_3", 3) ImportStaticLod("lod_4", 4) ImportStaticLod("lod_5", 5) elif asset_data["type"] == "SkeletalMesh": ImportSkeletalLod("lod_1", 1) ImportSkeletalLod("lod_2", 2) ImportSkeletalLod("lod_3", 3) ImportSkeletalLod("lod_4", 4) ImportSkeletalLod("lod_5", 5) # Vertex color if vertex_override_color: asset_import_data.set_editor_property( 'vertex_override_color', vertex_override_color.to_rgbe()) if vertex_color_import_option: asset_import_data.set_editor_property( 'vertex_color_import_option', vertex_color_import_option) # #################################[EndChange] if asset_data["type"] == "StaticMesh" or asset_data[ "type"] == "SkeletalMesh": unreal.EditorAssetLibrary.save_loaded_asset(asset) ImportedList.append([asset, asset_data["type"]])