using current file to render and add validator for deadline publish in max hosts

This commit is contained in:
Kayla Man 2023-05-29 19:25:49 +08:00
parent 4a4677b578
commit 9d9eebfe09
6 changed files with 72 additions and 77 deletions

View file

@ -38,7 +38,7 @@ class RenderProducts(object):
}
return render_dict
def get_aovs(self, container):
def get_aovs(self, container, instance):
render_dir = os.path.dirname(rt.rendOutputFilename)
output_file = os.path.join(render_dir,
@ -71,7 +71,7 @@ class RenderProducts(object):
if renderer == "Redshift_Renderer":
render_name = self.get_render_elements_name()
if render_name:
rs_AovFiles = rt.Redshift_Renderer().SeparateAovFiles
rs_AovFiles = instance.data.get("separateAovFiles")
if img_fmt == "exr" and not rs_AovFiles:
for name in render_name:
if name == "RsCryptomatte":

View file

@ -2,6 +2,7 @@
"""Creator plugin for creating camera."""
import os
from openpype.hosts.max.api import plugin
from openpype.lib import BoolDef
from openpype.pipeline import CreatedInstance
from openpype.hosts.max.api.lib_rendersettings import RenderSettings
@ -18,6 +19,9 @@ class CreateRender(plugin.MaxCreator):
file = rt.maxFileName
filename, _ = os.path.splitext(file)
instance_data["AssetName"] = filename
instance_data["separateAovFiles"] = (
pre_create_data.get("separateAovFiles"))
instance = super(CreateRender, self).create(
subset_name,
instance_data,
@ -40,3 +44,13 @@ class CreateRender(plugin.MaxCreator):
RenderSettings().set_render_camera(sel_obj)
# set output paths for rendering(mandatory for deadline)
RenderSettings().render_output(container_name)
def get_pre_create_attr_defs(self):
attrs = super(CreateRender, self).get_pre_create_attr_defs()
return attrs + [
BoolDef("separateAovFiles",
label="Separate Aov Files",
default=False),
]

View file

@ -6,7 +6,7 @@ import pyblish.api
from pymxs import runtime as rt
from openpype.pipeline import get_current_asset_name
from openpype.hosts.max.api import colorspace
from openpype.hosts.max.api.lib import get_max_version
from openpype.hosts.max.api.lib import get_max_version, get_current_renderer
from openpype.hosts.max.api.lib_renderproducts import RenderProducts
from openpype.client import get_last_version_by_subset_name
@ -31,12 +31,14 @@ class CollectRender(pyblish.api.InstancePlugin):
files_by_aov = RenderProducts().get_beauty(instance.name)
folder = folder.replace("\\", "/")
aovs = RenderProducts().get_aovs(instance.name)
aovs = RenderProducts().get_aovs(instance.name, instance)
files_by_aov.update(aovs)
if "expectedFiles" not in instance.data:
instance.data["expectedFiles"] = list()
instance.data["files"] = list()
instance.data["expectedFiles"].append(files_by_aov)
instance.data["files"].append(files_by_aov)
img_format = RenderProducts().image_format()
project_name = context.data["projectName"]
@ -62,6 +64,8 @@ class CollectRender(pyblish.api.InstancePlugin):
instance.data["renderProducts"] = colorspace.ARenderProduct()
instance.data["publishJobState"] = "Suspended"
instance.data["attachTo"] = []
renderer_class = get_current_renderer()
renderer = str(renderer_class).split(":")[0]
# also need to get the render dir for coversion
data = {
"asset": asset,
@ -71,6 +75,7 @@ class CollectRender(pyblish.api.InstancePlugin):
"imageFormat": img_format,
"family": 'maxrender',
"families": ['maxrender'],
"renderer": renderer,
"source": filepath,
"plugin": "3dsmax",
"frameStart": int(rt.rendStart),

View file

@ -18,9 +18,4 @@ class SaveCurrentScene(pyblish.api.ContextPlugin):
file = rt.maxFileName
current = os.path.join(folder, file)
assert context.data["currentFile"] == current
if rt.checkForSave():
self.log.debug("Skipping file save as there "
"are no modifications..")
return
rt.saveMaxFile(current)

View file

@ -0,0 +1,41 @@
import os
import pyblish.api
from pymxs import runtime as rt
from openpype.pipeline.publish import (
RepairAction,
ValidateContentsOrder,
PublishValidationError,
OptionalPyblishPluginMixin
)
from openpype.hosts.max.api.lib_rendersettings import RenderSettings
class ValidateDeadlinePublish(pyblish.api.InstancePlugin,
OptionalPyblishPluginMixin):
"""Validates Render File Directory is
not the same in every submission
"""
order = ValidateContentsOrder
families = ["maxrender"]
hosts = ["max"]
label = "Render Output for Deadline"
optional = True
actions = [RepairAction]
def process(self, instance):
if not self.is_active(instance.data):
return
file = rt.maxFileName
filename, ext = os.path.splitext(file)
if filename not in rt.rendOutputFilename:
raise PublishValidationError(
"Directory of RenderOutput doesn't "
"have with the current Max SceneName "
"please repair to rename the folder!"
)
@classmethod
def repair(cls, instance):
container= instance.data.get("instance_node")
RenderSettings().render_output(container)

View file

@ -133,6 +133,7 @@ class MaxSubmitDeadline(abstract_submit_deadline.AbstractSubmitDeadline,
# Add list of expected files to job
# ---------------------------------
exp = instance.data.get("expectedFiles")
for filepath in self._iter_expected_files(exp):
job_info.OutputDirectory += os.path.dirname(filepath)
job_info.OutputFilename += os.path.basename(filepath)
@ -204,8 +205,6 @@ class MaxSubmitDeadline(abstract_submit_deadline.AbstractSubmitDeadline,
old_output_dir = os.path.dirname(first_file)
output_beauty = RenderSettings().get_render_output(instance.name,
old_output_dir)
files = instance.data["expectedFiles"]
first_file = next(self._iter_expected_files(files))
rgb_bname = os.path.basename(output_beauty)
dir = os.path.dirname(first_file)
beauty_name = f"{dir}/{rgb_bname}"
@ -231,6 +230,9 @@ class MaxSubmitDeadline(abstract_submit_deadline.AbstractSubmitDeadline,
new_elem = new_elem.replace("/", "\\")
plugin_data["RenderElementOutputFilename%d" % i] = new_elem # noqa
if renderer == "Redshift_Renderer":
plugin_data["redshift_SeparateAovFiles"] = instance.data.get(
"separateAovFiles", False)
self.log.debug("plugin data:{}".format(plugin_data))
plugin_info.update(plugin_data)
@ -239,72 +241,10 @@ class MaxSubmitDeadline(abstract_submit_deadline.AbstractSubmitDeadline,
def from_published_scene(self, replace_in_path=True):
instance = self._instance
workfile_instance = self._get_workfile_instance(instance.context)
if workfile_instance is None:
return
# determine published path from Anatomy.
template_data = workfile_instance.data.get("anatomyData")
rep = workfile_instance.data["representations"][0]
template_data["representation"] = rep.get("name")
template_data["ext"] = rep.get("ext")
template_data["comment"] = None
anatomy = instance.context.data['anatomy']
template_obj = anatomy.templates_obj["publish"]["path"]
template_filled = template_obj.format_strict(template_data)
file_path = os.path.normpath(template_filled)
self.log.info("Using published scene for render {}".format(file_path))
if not os.path.exists(file_path):
self.log.error("published scene does not exist!")
raise
if not replace_in_path:
return file_path
# now we need to switch scene in expected files
# because <scene> token will now point to published
# scene file and that might differ from current one
def _clean_name(path):
return os.path.splitext(os.path.basename(path))[0]
new_scene = _clean_name(file_path)
orig_scene = _clean_name(instance.data["AssetName"])
expected_files = instance.data.get("expectedFiles")
if isinstance(expected_files[0], dict):
# we have aovs and we need to iterate over them
new_exp = {}
for aov, files in expected_files[0].items():
replaced_files = []
for f in files:
replaced_files.append(
str(f).replace(orig_scene, new_scene)
)
new_exp[aov] = replaced_files
# [] might be too much here, TODO
instance.data["expectedFiles"] = [new_exp]
else:
new_exp = []
for f in expected_files:
new_exp.append(
str(f).replace(orig_scene, new_scene)
)
instance.data["expectedFiles"] = new_exp
metadata_folder = instance.data.get("publishRenderMetadataFolder")
if metadata_folder:
metadata_folder = metadata_folder.replace(orig_scene,
new_scene)
instance.data["publishRenderMetadataFolder"] = metadata_folder
self.log.info("Scene name was switched {} -> {}".format(
orig_scene, new_scene
))
return file_path
if instance.data["renderer"] == "Redshift_Renderer":
self.log.debug("Using Redshift...published scene wont be used..")
replace_in_path = False
return replace_in_path
@staticmethod
def _iter_expected_files(exp):