Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 105 additions & 17 deletions client/ayon_deadline/plugins/publish/max/submit_max_deadline.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
from dataclasses import dataclass, field, asdict

from ayon_core.pipeline import (
AYONPyblishPluginMixin
)
from ayon_core.pipeline.publish.lib import (
replace_with_published_scene_path
AYONPyblishPluginMixin,
tempdir
)
from ayon_core.pipeline.publish import KnownPublishError
from ayon_max.api.lib import (
Expand Down Expand Up @@ -146,6 +144,11 @@ def _use_published_name(self, data, project_settings):
if renderer == "Redshift_Renderer":
plugin_data["redshift_SeparateAovFiles"] = instance.data.get(
"separateAovFiles")

elif renderer.startswith("V_Ray_"):
# enable this so that V-Ray frame buffer shows up
plugin_data["ShowFrameBuffer"] = True

if instance.data["cameras"]:
camera = instance.data["cameras"][0]
plugin_info["Camera0"] = camera
Expand All @@ -157,6 +160,12 @@ def _use_published_name(self, data, project_settings):
plugin_info["RenderHeight"] = instance.data.get(
"resolutionHeight", rt.renderHeight)

published_workfile = os.path.basename(plugin_info["SceneFile"])
plugin_info["PostLoadScript"] = tmp_pre_load_max_script(
instance,
instance.data["original_workfile_pattern"],
os.path.splitext(published_workfile)[0],
)
self.log.debug("plugin data:{}".format(plugin_data))
plugin_info.update(plugin_data)

Expand Down Expand Up @@ -258,19 +267,6 @@ def _use_published_name_for_multiples(self, data, project_settings):

return job_info_list, plugin_info_list

def from_published_scene(self, replace_in_path=True):
instance = self._instance
renderer = instance.data["renderer"]
# Max does not support edit render settings in the headless mode
# so we would not use published scene for renderers.
if self._is_unsupported_renderer_for_published_scene(renderer):
self.log.debug(
f"Using {renderer}...published scene wont be used.."
)
replace_in_path = False
return replace_with_published_scene_path(
instance, replace_in_path)

@staticmethod
def _is_unsupported_renderer_for_published_scene(renderer):
"""Check if renderer doesn't support published scene files."""
Expand Down Expand Up @@ -326,3 +322,95 @@ def _iter_expected_files(exp):
else:
for file in exp:
yield file


def tmp_pre_load_max_script(instance, original_workfile, publish_workfile):
"""Temporary function to provide pre-load maxscript for deadline
submission. This is a workaround for Deadline issue where it
doesn't load the scene properly before rendering.

Returns:
str: Maxscript code as a string.
"""
temp_dir = tempdir.get_temp_dir(
instance.context.data["projectName"],
use_local_temp=True)

max_script = f"""
fn PublishWorkfileRenderOutput =
(
rendererName = renderers.production as string
original_workfile = "{original_workfile}"
publish_workfile = "{publish_workfile}"

if matchPattern rendererName pattern:"V_Ray*" then
(
if matchPattern rendererName pattern:"*GPU*" then
(
original_filename = renderers.production.V_Ray_settings.output_rawfilename
new_filename = substituteString original_filename original_workfile publish_workfile
renderers.production.V_Ray_settings.output_rawfilename = new_filename

if renderers.production.V_Ray_settings.output_splitgbuffer do
(
original_Aovfilename = renderers.production.V_Ray_settings.output_splitfilename
new_aovfilename = substituteString original_Aovfilename original_workfile publish_workfile
renderers.production.V_Ray_settings.output_splitfilename = new_aovfilename
)
)
else
(
original_filename = renderers.production.output_rawfilename
new_filename = substituteString original_filename original_workfile publish_workfile
renderers.production.output_rawfilename = new_filename

if renderers.production.output_splitgbuffer do
(
original_Aovfilename = renderers.production.output_splitfilename
new_aovfilename = substituteString original_Aovfilename original_workfile publish_workfile
renderers.production.output_splitfilename = new_aovfilename
)
)
)
else
(
original_filename = renderOutput
new_filename = substituteString original_filename original_workfile publish_workfile
renderOutput = new_filename

rnMgr = maxOps.GetCurRenderElementMgr()
if rnMgr != undefined do
(
for i = 1 to rnMgr.numrenderelements() do
(
re = rnMgr.getrenderelement i
if re.enabled do
(
originAovfilename = re.GetRenderElementFileName i
if originAovfilename != undefined and originAovfilename != "" do
(
newAovfilename = substituteString originAovfilename original_workfile publish_workfile
re.SetRenderElementFileName i newAovfilename
)
)
)
)
)

return true
)

-- Execute the function
renderOutputPublish = PublishWorkfileRenderOutput()

""" # noqa: E501

script_path = os.path.join(temp_dir, "pre_load_max_script.ms")

try:
with open(script_path, "w") as script_file:
script_file.write(max_script)
print(f"Temporary pre-load maxscript created at: {script_path}")
return script_path
except Exception as e:
raise RuntimeError(f"Error creating maxscript file: {str(e)}")
Loading