1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
| editor_level_subsystem = unreal.get_editor_subsystem(unreal.LevelEditorSubsystem) def get_content_browser_selection(): assets = unreal.EditorUtilityLibrary.get_selected_assets()
def show_assets_in_cb(paths=None): if paths = None: paths = [] elif type(paths) is str: paths = [paths] elif type(paths) is list: pass else: raise Exception("Unknown value {} in parameter paths".format(paths)) unreal.EditorAssetLibrary.sync_browser_to_objects(asset_paths=paths)
def show_current_level_in_cb(): level_path = editor_level_subsystem.get_current_level().get_path_name() show_assets_in_cb([level_path]) return level_path
def open_assets_in_editor(paths=None): if paths is None: paths = [] elif type(paths) is str: paths = [paths] else: raise Exception("Unknown value {} in parameter paths".format(paths)) loaded_assets = [get_asset_by_path(x) for x in paths] asset_tools.open_editor_for_assets(assets=loaded_assets)
def asset_exists(path=""): return unreal.EditorAssetLibrary.does_asset_exist(asset_path=path)
def get_material_instance_constant_parameter(mi_asset_path, parameter_name): mi_asset = get_asset_by_path(mi_asset_path)
scalars = unreal.MaterialEditingLibrary.get_scalar_parameter_names(mi_asset) switches = unreal.MaterialEditingLibrary.get_static_switch_parameter(mi_asset) textures = unreal.MaterialEditingLibrary.get_texture_parameter_names(mi_asset) vectors = unreal.MaterialEditingLibrary.get_vector_parameter_names(mi_asset)
if parameter_name in scalars: getter = unreal.MaterialEditingLibrary.get_material_instance_scalar_parameter_value elif parameter_name in switches: getter = unreal.MaterialEditingLibrary.get_material_instance_static_switch_parameter_value elif parameter_name in textures: getter = unreal.MaterialEditingLibrary.get_material_instance_texture_parameter_value elif parameter_name in vectors: getter = unreal.MaterialEditingLibrary.get_material_instance_vector_parameter_value parameter_value = getter(instance=mi_asset, parameter_name=parameter_name) return parameter_value
def duplicate_asset(from_path='', to_path=''): return unreal.EditorAssetLibrary.duplicate_asset( source_asset_path = from_path, destination_asset_path=to_path )
def rename_asset(from_path='', to_path=''): return unreal.EditorAssetLibrary.rename_asset( source_asset_path = from_path, destination_asset_path = to_path
def delete _asset(path=""): if not path: return elif asset_exists(path): return unreal.EditorAssetLibrary.delete_asset(asset_path_to_delete=path) )
def save_asset(path='', force_save=True): return unreal.EditorAssetLibrary.save_asset( asset_to_save=path, only_if_is_dirty=not force_save )
def create_generic_asset(asset_path="", asset_class=None, asset_factory=None, unique_name=True): """ _path + 'sequence', unreal.LevelSequence, unreal.LevelSequenceFactoryNew(), _path + 'material' unreal.Material, unreal.MaterialFactoryNew(), _path+'world' unreal.World, unreal.WorldFactory(), _path+'particle_system' unreal.ParticalSystem, unreal.ParticleSystemFactoryNew() _path+ 'paper_flipbook' _path+ 'data_struc' """ if unique_name: asset_path, asset_name = asset_tools.create_unique_asset_name( base_package_name = asset_path, suffix='' ) if not unreal.EditorAssetLibrary.does_asset_exist(asset_path=asset_path): _path_ = os.path.dirname(asset_path) _name_ = os.path.basename(asset_path) return asset_tools.create_asset( asset_name=_name_, package_path=_path_, asset_class=asset_class, factory=asset_factory ) return unreal.load_asset(asset_path)
def create_material_instance_constant(parent_mat_path, mi_asset_name=None): if not mi_asset_name: parent_material_basename = os.path.basename(parent_material_path).split('.')[0] mi_asset__name = parent_material_basename + "_inst" mi_asset_directory = os.path.dirname(parent_material_path) mi_asset_path = "/".join([mi_asset_directory, mi_asset_name]) mi_asset = create_generic_asset( asset_path=mi_asset_path, asset_class=unreal.MaterialInstanceConstant, asset_factory=unreal.MaterialIntanceConstantFactoryNew() ) unreal.MaterialEditingLibrary.set_material_instance_parent(mi_asset, parent_mat_path) return mi_asset_path
def build_import_task(filename='', dest_path='', dest_name=None,opetions=None): task = unreal.AssetImportTask() task.automated = True if dest_name is not None: task.destination_name = dest_name task.destination_path = dest_path task.filename = filename
task.replace_existing =True task.set_editor_property('options', options) return task
def execute_import_tasks(tasks=None): if tasks is None: tasks = [] asset_tools.import_asset_tasks(tasks) imported_asset_paths = [] for task in tasks: for path in task.get_editor_property('imported_object_paths'): imported_asset_paths.append(path) return imported_asset_paths
def build_static_mesh_import_options(): options = unreal.FbxImportUI() options.import_mesh = True options.mesh_type_to_import = unreal.FBXImportType.FBXIT_STATIC_MESH options.import_textures = False options.import_materials = False options.import_as_skeletal = False
import_data = options.static_mesh_import_data import_data.import_translation = unreal.Vector(0,0,0) import_data.import_rotation = unreal.Rotator(0,0,0) import_data.import_uniform_scale = 1.0 import_data.set_editor_property('combine_meshes', True) import_data.set_editor_property('generate_lightmap_u_vs', True) import_data.set_editor_property('auto_generate_collision', True) return options
def build_skelecton_mesh_import_options(skeletion_path=None): options = unreal.FbxImportUI() options.import_mesh = True options.import_as_skeletal = True options.mesh_type_to_import = unreal.FBXImportType.FBXIT_SKELETAL_MESH options.import_textures = False options.import_materials = False options.create_physics_asset = False
if skeleton_path is None: options.skeleton = skeleton_path else: options.skeleton = unreal.load_asset(skeleton_path) import_data = options.static_mesh_import_data import_data.import_translation = unreal.Vector(0,0,0) import_data.import_rotation = unreal.Rotator(0,0,0) import_data.import_uniform_scale = 1.0 import_data.set_editor_property('import_morph_targets', True) import_data.set_editor_property('update_skeleton_reference_pose', False) return options
def example_import_csv_asset(): source = "{}".format(csv_file_path) directory = "{}".format(saved_path) struct_path = "{}".format(path of whcih struch you want to import csv)
datatable_task = build_import_task(source, directory) factory = unreal.CSVImportFactory() factory.automated_import_settings.import_row_struct = get_asset_by_path(struct_path) datatabale_task.factory = factory unreal.log(execute_import_tasks([datatable_task]))
|