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
| """ 渲染 sequencer 的画面 选择 LevelSequence 批量进行渲染 """
from __future__ import division from __future__ import print_function from __future__ import absolute_import
__author__ = 'timmyliang' __email__ = '820472580@qq.com' __date__ = '2020-07-14 21:57:32'
import unreal
import os import subprocess from functools import partial
def alert(msg): unreal.SystemLibrary.print_string(None,msg,text_color=[255,255,255,255])
def render(sequence_list,i,output_directory="C:/render",output_format="{sequence}"): if i >= len(sequence_list): subprocess.call(["start","",output_directory], creationflags=0x08000000,shell=True) return
sequence = sequence_list[i]
settings = unreal.MovieSceneCaptureSettings() path = unreal.DirectoryPath(output_directory) settings.set_editor_property("output_directory",path) settings.set_editor_property("output_format",output_format) settings.set_editor_property("overwrite_existing",True) settings.set_editor_property("game_mode_override",None) settings.set_editor_property("use_relative_frame_numbers",False) settings.set_editor_property("handle_frames",0) settings.set_editor_property("zero_pad_frame_numbers",4) settings.set_editor_property("use_custom_frame_rate",True) settings.set_editor_property("custom_frame_rate",unreal.FrameRate(24, 1))
w,h = 1280,720 settings.set_editor_property("resolution",unreal.CaptureResolution(w,h)) settings.set_editor_property("enable_texture_streaming",False) settings.set_editor_property("cinematic_engine_scalability",True) settings.set_editor_property("cinematic_mode",True) settings.set_editor_property("allow_movement",False) settings.set_editor_property("allow_turning",False) settings.set_editor_property("show_player",False) settings.set_editor_property("show_hud",False)
option = unreal.AutomatedLevelSequenceCapture() option.set_editor_property("use_separate_process",False) option.set_editor_property("close_editor_when_capture_starts",False) option.set_editor_property("additional_command_line_arguments","-NOSCREENMESSAGES") option.set_editor_property("inherited_command_line_arguments","") option.set_editor_property("use_custom_start_frame",False) option.set_editor_property("use_custom_end_frame",False) option.set_editor_property("warm_up_frame_count",0.0) option.set_editor_property("delay_before_warm_up",0) option.set_editor_property("delay_before_shot_warm_up",0.0) option.set_editor_property("write_edit_decision_list",True) option.set_editor_property("settings",settings) option.set_editor_property("level_sequence_asset",unreal.SoftObjectPath(sequence.get_path_name()))
option.set_image_capture_protocol_type(unreal.CompositionGraphCaptureProtocol) protocol = option.get_image_capture_protocol() passes = unreal.CompositionGraphCapturePasses(["Base Color"]) protocol.set_editor_property("include_render_passes",passes)
global on_finished_callback on_finished_callback = unreal.OnRenderMovieStopped( lambda s:render(sequence_list,i+1,output_directory,output_format)) unreal.SequencerTools.render_movie(option,on_finished_callback)
def main(output_directory="C:/render",output_format="{sequence}"): sequence_list = [asset for asset in unreal.EditorUtilityLibrary.get_selected_assets() if isinstance(asset,unreal.LevelSequence)]
if not sequence_list: alert(u"请选择一个 LevelSequence") return
if not os.access(output_directory, os.W_OK): alert(u"当前输出路径非法") return elif not os.path.exists(output_directory): os.makedirs(output_directory) elif os.path.isfile(output_directory): output_directory = os.path.dirname(output_directory)
render(sequence_list,0,output_directory,output_format)
if __name__ == "__main__": main()
|