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 | class UnrealSubmitDeadline(
abstract_submit_deadline.AbstractSubmitDeadline
):
"""Supports direct rendering of prepared Unreal project on Deadline
(`render` product must be created with flag for Farm publishing) OR
Perforce assisted rendering.
For this Ayon server must contain `ayon-version-control` addon and provide
configuration for it (P4 credentials etc.)!
"""
label = "Submit Unreal to Deadline"
order = pyblish.api.IntegratorOrder + 0.1
hosts = ["unreal"]
families = ["render.farm"] # cannot be "render' as that is integrated
targets = ["local"]
def get_job_info(self, job_info=None):
instance = self._instance
job_info.BatchName = self._get_batch_name()
job_info.Plugin = "UnrealEngine5"
if instance.data["frameEnd"] > instance.data["frameStart"]:
# Deadline requires integers in frame range
frame_range = "{}-{}".format(
int(round(instance.data["frameStart"])),
int(round(instance.data["frameEnd"])))
job_info.Frames = frame_range
return job_info
def get_plugin_info(self):
deadline_plugin_info = DeadlinePluginInfo()
render_path = self._instance.data["expectedFiles"][0]
self._instance.data["outputDir"] = os.path.dirname(render_path)
self._instance.context.data["version"] = 1 #TODO
render_dir = os.path.dirname(render_path)
file_name = self._instance.data["file_names"][0]
render_path = os.path.join(render_dir, file_name)
deadline_plugin_info.ProjectFile = self.scene_path
deadline_plugin_info.Output = render_path.replace("\\", "/")
deadline_plugin_info.EditorExecutableName = "UnrealEditor-Cmd.exe"
deadline_plugin_info.EngineVersion = self._instance.data["app_version"]
master_level = self._instance.data["master_level"]
render_queue_path = self._instance.data["render_queue_path"]
cmd_args = [
master_level,
"-game",
f"-MoviePipelineConfig={render_queue_path}",
"-windowed",
"-Log",
"-StdOut",
"-allowStdOutLogVerbosity",
"-Unattended",
]
self.log.debug(f"cmd-args::{cmd_args}")
deadline_plugin_info.CommandLineArguments = " ".join(cmd_args)
# if Perforce - triggered by active `changelist_metadata` instance!!
collected_version_control = self._get_version_control()
if collected_version_control:
version_control_data = self._instance.context.data[
"version_control"]
workspace_dir = version_control_data["workspace_dir"]
stream = version_control_data["stream"]
self._update_version_control_data(
self.scene_path,
workspace_dir,
stream,
collected_version_control["change_info"]["change"],
deadline_plugin_info,
)
return asdict(deadline_plugin_info)
def from_published_scene(self, replace_in_path=True):
""" Do not overwrite expected files.
Use published is set to True, so rendering will be triggered
from published scene (in 'publish' folder). Default implementation
of abstract class renames expected (eg. rendered) files accordingly
which is not needed here.
"""
return super().from_published_scene(False)
def _get_batch_name(self):
"""Returns value that differentiate jobs in DL.
For automatic tests it adds timestamp, for Perforce driven change list
"""
batch_name = os.path.basename(self._instance.data["source"])
if is_in_tests():
batch_name += datetime.now().strftime("%d%m%Y%H%M%S")
collected_version_control = self._get_version_control()
if collected_version_control:
change = (collected_version_control["change_info"]
["change"])
batch_name = f"{batch_name}_{change}"
return batch_name
def _get_version_control(self):
"""Look if changelist_metadata is published to get change list info.
Context version_control contains universal connection info, instance
version_control contains detail about change list.
"""
change_list_version = {}
for inst in self._instance.context:
# get change info from `changelist_metadata` instance
change_list_version = inst.data.get("version_control")
if change_list_version:
context_version = (
self._instance.context.data["version_control"])
change_list_version.update(context_version)
break
return change_list_version
def _update_version_control_data(
self,
scene_path,
workspace_dir,
stream,
change_list_id,
deadline_plugin_info,
):
"""Adds Perforce metadata which causes DL pre job to sync to change.
It triggers only in presence of activated `changelist_metadata`
instance, which materialize info about commit. Artists could return
to any published commit and re-render if they choose.
`changelist_metadata` replaces `workfile` as there are no versioned
Unreal projects (because of size).
"""
# normalize paths, c:/ vs C:/
scene_path = str(Path(scene_path).resolve())
workspace_dir = str(Path(workspace_dir).resolve())
unreal_project_file_name = os.path.basename(scene_path)
unreal_project_hierarchy = self.scene_path.replace(workspace_dir, "")
unreal_project_hierarchy = (
unreal_project_hierarchy.replace(unreal_project_file_name, ""))
# relative path from workspace dir to last folder
unreal_project_hierarchy = unreal_project_hierarchy.strip("\\")
deadline_plugin_info.ProjectFile = unreal_project_file_name
deadline_plugin_info.PerforceStream = stream
deadline_plugin_info.PerforceChangelist = change_list_id
deadline_plugin_info.PerforceGamePath = unreal_project_hierarchy
|