/
Manifest
/
Real_Texture
Обзор
Документация
Войти
/
Manifest
/
Real_Texture
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
ToolsPythonForSequenceInUE/MaxTextureSize.py
120 строк
6 KB
m.samodurov
init commit for The Invaders
17 фев 2026, 04:57
17 фев 2026, 04:57
4a668d4
Код
Авторство
О чём код?
import unreal """======================================================================================================""" """=================================РЕДАКТИРУЕМЫЕ ПАРАМЕТРЫ==============================================""" """======================================================================================================""" # Настройки изменения разрешения текстур MIN_TEXTURE_SIZE = 128 MAX_TEXTURE_SIZE = 2048 MIN_DISTANCE = 100 # Минимальное расстояние (при котором будет максимальное разрешение) MAX_DISTANCE = 500 # Максимальное расстояние (при котором будет минимальное разрешение) """======================================================================================================""" def get_camera_actor(): """ Получает единственный CineCameraActor в сцене. """ editor_actor_subsystem = unreal.get_editor_subsystem(unreal.EditorActorSubsystem) all_actors = editor_actor_subsystem.get_all_level_actors() for actor in all_actors: if isinstance(actor, unreal.CineCameraActor): return actor return None def get_all_static_mesh_actors(): """ Получает все Static Mesh в сцене. """ editor_actor_subsystem = unreal.get_editor_subsystem(unreal.EditorActorSubsystem) return [actor for actor in editor_actor_subsystem.get_all_level_actors() if isinstance(actor, unreal.StaticMeshActor)] def get_distance_to_camera(camera, actor): """ Возвращает расстояние от камеры до объекта. """ camera_location = camera.get_actor_location() actor_location = actor.get_actor_location() return (camera_location - actor_location).length() def calculate_texture_size(distance): """ Вычисляет новое разрешение текстуры на основе расстояния до камеры. """ clamped_distance = max(MIN_DISTANCE, min(distance, MAX_DISTANCE)) # Теперь scale увеличивается с расстоянием (0 -> 1) scale = (clamped_distance - MIN_DISTANCE) / (MAX_DISTANCE - MIN_DISTANCE) # Инвертируем размер: чем дальше, тем меньше разрешение new_size = int((1 - scale) * (MAX_TEXTURE_SIZE - MIN_TEXTURE_SIZE) + MIN_TEXTURE_SIZE) # Округляем до ближайшей степени 2 power_of_two_sizes = [128, 256, 512, 1024, 2048] # тут можно рассчитывать через параметры MAX_TEXTURE_SIZE и MIN_TEXTURE_SIZE new_size = min(power_of_two_sizes, key=lambda x: abs(x - new_size)) return new_size def get_textures_from_material(material_instance): """ Получает все текстуры из параметров Material Instance. """ texture_params = material_instance.get_editor_property("texture_parameter_values") return [param.parameter_value for param in texture_params if param.parameter_value] def update_texture_sizes(actor, camera, processed_meshes, processed_textures): """ Обновляет MaxTextureSize для текстур в Material Instance на основе расстояния. """ static_mesh_component = actor.get_component_by_class(unreal.StaticMeshComponent) if not static_mesh_component: return static_mesh = static_mesh_component.get_editor_property("static_mesh") if not static_mesh: return # Если у компонента нет Static Mesh, просто выходим processed_meshes.add(static_mesh) # Добавляем в список обработанных distance = get_distance_to_camera(camera, actor) new_size = calculate_texture_size(distance) material_count = static_mesh_component.get_num_materials() for i in range(material_count): material = static_mesh_component.get_material(i) if isinstance(material, unreal.MaterialInstanceConstant): textures = get_textures_from_material(material) for texture in textures: if texture in processed_textures: # Если текстура уже обработана, пропускаем continue processed_textures.add(texture) # Добавляем в список обработанных texture_path = texture.get_path_name() if unreal.EditorAssetLibrary.does_asset_exist(texture_path): texture_asset = unreal.EditorAssetLibrary.load_asset(texture_path) if texture_asset: texture_asset.modify(True) if isinstance(texture_asset, unreal.Texture2D): # Проверяем, что это текстура old_size = texture_asset.blueprint_get_size_x() texture_asset.set_editor_property("max_texture_size", new_size) # Самая важная функция - изменение MaxTextureSize unreal.EditorAssetLibrary.save_asset(texture_path) print( f"[UPDATED] {texture.get_name()} {old_size} -> {new_size}px (Distance: {int(distance)} units)") else: print(f"[SKIPPED] {texture.get_name()} не является Texture2D") def main(): camera = get_camera_actor() if not camera: print("CineCameraActor не найден!") return static_mesh_actors = get_all_static_mesh_actors() if not static_mesh_actors: print("В сцене нет Static Mesh!") return processed_meshes = set() # Кэш обработанных Static Mesh processed_textures = set() # Кэш обработанных текстур for actor in static_mesh_actors: update_texture_sizes(actor, camera, processed_meshes, processed_textures) if __name__ == "__main__": main()