Files
samford-valley-home/source/samford-v008-tesla/unreal-daylight.py

45 lines
4.2 KiB
Python

import unreal as u,time,json,math
from pathlib import Path
P=Path(__file__).resolve().parents[3];A=u.get_editor_subsystem(u.EditorActorSubsystem);E=u.get_editor_subsystem(u.LevelEditorSubsystem);L=u.EditorAssetLibrary;S=u.get_editor_subsystem(u.StaticMeshEditorSubsystem);world=u.get_editor_subsystem(u.UnrealEditorSubsystem).get_editor_world();actors=A.get_all_level_actors();u.EditorPythonScripting.set_keep_python_script_alive(True)
def prop(o,k,v):o.set_editor_property(k,v)
# Resolve the actual imported slot names; FBX can reorder slots.
slots=[]
for path in L.list_assets('/Game/LicensedTesla/Meshes',recursive=True):
mesh=L.load_asset(path)
if not isinstance(mesh,u.StaticMesh):continue
for i,slot in enumerate(mesh.static_materials):
key=str(slot.get_editor_property('imported_material_slot_name'))
material=L.load_asset('/Game/LicensedTesla/Materials/'+key)
assert material,('Missing imported material slot',mesh.get_name(),key)
mesh.set_material(i,material);slots.append([mesh.get_name(),i,key])
if mesh.get_name().endswith('Tesla_7K'):
S.remove_collisions(mesh);S.add_simple_collisions(mesh,u.ScriptCollisionShapeType.BOX);prop(mesh.get_editor_property('body_setup'),'collision_trace_flag',u.CollisionTraceFlag.CTF_USE_SIMPLE_AND_COMPLEX)
L.save_loaded_asset(mesh)
sun=next(a for a in actors if isinstance(a,u.DirectionalLight));sun.set_actor_label('Clear daytime sun');sun.set_actor_rotation(u.MathLibrary.find_look_at_rotation(u.Vector(1200,-1400,2400),u.Vector(0,0,0)),False);sun.light_component.set_intensity(65000);sun.light_component.set_light_color(u.LinearColor(1,.96,.88,1));prop(sun.light_component,'light_source_angle',1.0);prop(sun.light_component,'indirect_lighting_intensity',2.5)
for a in actors:
if isinstance(a,u.SkyLight):
a.light_component.set_intensity(3.5);prop(a.light_component,'real_time_capture',True)
if isinstance(a,u.ExponentialHeightFog):prop(a.component,'fog_density',.001)
if isinstance(a,u.PostProcessVolume):
p=a.settings
for k,v in dict(override_auto_exposure_min_brightness=True,override_auto_exposure_max_brightness=True,auto_exposure_min_brightness=5.5,auto_exposure_max_brightness=11.0,override_auto_exposure_bias=True,auto_exposure_bias=1.2,override_auto_exposure_speed_up=True,auto_exposure_speed_up=3.0,override_auto_exposure_speed_down=True,auto_exposure_speed_down=2.0,override_lumen_scene_lighting_quality=True,lumen_scene_lighting_quality=2.0,override_lumen_final_gather_quality=True,lumen_final_gather_quality=2.0).items():prop(p,k,v)
prop(a,'settings',p)
if isinstance(a,u.RectLight):
a.light_component.set_light_color(u.LinearColor(1,.97,.91,1))
if a.get_actor_label()=='Garage presentation fill':a.light_component.set_intensity(9000)
elif 'verandah bounce' in a.get_actor_label():a.light_component.set_intensity(6000)
E.save_current_level();L.save_directory('/Game/LicensedTesla',only_if_is_dirty=True,recursive=True)
r={'sun_lux':65000,'sun_elevation_degrees':52,'sky_intensity':3.5,'exposure_EV_range':[5.5,11.0],'exposure_bias':1.2,'material_slots_resolved_by_imported_name':slots,'car_collision':'simple box for walking, detail triangles retained for complex traces','level_saved':True}
(P/'unreal-daylight-checks.json').write_text(json.dumps(r,indent=2))
for c in ['r.HighResScreenshotDelay 64','r.AntiAliasingMethod 2','r.TemporalAASamples 64']:u.SystemLibrary.execute_console_command(world,c)
cams=[next(a for a in actors if a.get_actor_label()==n) for n in ['CAM - Verandah','CAM - Overview','CAM - Licensed Tesla garage']];state={'start':time.monotonic(),'i':0,'task':None}
def tick(dt):
if time.monotonic()-state['start']<30:return
if state['task'] is None:
u.AutomationLibrary.finish_loading_before_screenshot();cam=cams[state['i']];u.EditorLevelLibrary.set_level_viewport_camera_info(cam.get_actor_location(),cam.get_actor_rotation());state['task']=u.AutomationLibrary.take_high_res_screenshot(1600,1000,str(P/'renders'/('daylight-'+['verandah','overview','tesla'][state['i']]+'.png')),camera=cam,delay=5)
elif state['task'].is_task_done():
state['i']+=1;state['task']=None
if state['i']==3:
u.unregister_slate_post_tick_callback(handle);u.log('DAYLIGHT_CAPTURED');u.SystemLibrary.quit_editor()
handle=u.register_slate_post_tick_callback(tick)