Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Max: Optional Renderable Camera Validator for Render Instance #5286

Merged
merged 14 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from 13 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
5 changes: 3 additions & 2 deletions openpype/hosts/max/api/lib_rendersettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def set_render_camera(self, selection):
rt.viewport.setCamera(sel)
break
if not found:
raise RuntimeError("Camera not found")
raise RuntimeError("Active Camera not found")

def render_output(self, container):
folder = rt.maxFilePath
Expand Down Expand Up @@ -113,7 +113,8 @@ def arnold_setup(self):
# for setting up renderable camera
arv = rt.MAXToAOps.ArnoldRenderView()
render_camera = rt.viewport.GetCamera()
arv.setOption("Camera", str(render_camera))
if render_camera:
arv.setOption("Camera", str(render_camera))

# TODO: add AOVs and extension
img_fmt = self._project_settings["max"]["RenderSettings"]["image_format"] # noqa
Expand Down
5 changes: 5 additions & 0 deletions openpype/hosts/max/plugins/publish/collect_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ def process(self, instance):
aovs = RenderProducts().get_aovs(instance.name)
files_by_aov.update(aovs)

camera = rt.viewport.GetCamera()
instance.data["cameras"] = None
moonyuet marked this conversation as resolved.
Show resolved Hide resolved
if camera:
instance.data["cameras"] = [camera.name]

if "expectedFiles" not in instance.data:
instance.data["expectedFiles"] = list()
instance.data["files"] = list()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class ValidateMaxContents(pyblish.api.InstancePlugin):
order = pyblish.api.ValidatorOrder
families = ["camera",
"maxScene",
"maxrender",
"review"]
hosts = ["max"]
label = "Max Scene Contents"
Expand Down
46 changes: 46 additions & 0 deletions openpype/hosts/max/plugins/publish/validate_renderable_camera.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# -*- coding: utf-8 -*-
import pyblish.api
from openpype.pipeline import (
PublishValidationError,
OptionalPyblishPluginMixin)
from openpype.pipeline.publish import RepairAction
from openpype.hosts.max.api.lib import get_current_renderer

from pymxs import runtime as rt


class ValidateRenderableCamera(pyblish.api.InstancePlugin,
OptionalPyblishPluginMixin):
"""Validates Renderable Camera

Check if the renderable camera used for rendering
"""

order = pyblish.api.ValidatorOrder
families = ["maxrender"]
hosts = ["max"]
label = "Renderable Camera"
optional = True
actions = [RepairAction]

def process(self, instance):
if not self.is_active(instance.data):
return
if not instance.data["cameras"]:
raise PublishValidationError(
"No renderable Camera found in scene."
)

@classmethod
def repair(cls, instance):

rt.viewport.setType(rt.Name("view_camera"))
camera = rt.viewport.GetCamera()
cls.log.info(f"Camera {camera} set as renderable camera")
renderer_class = get_current_renderer()
renderer = str(renderer_class).split(":")[0]
if renderer == "Arnold":
arv = rt.MAXToAOps.ArnoldRenderView()
arv.setOption("Camera", str(camera))
arv.close()
instance.data["cameras"] = [camera.name]
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class MaxPluginInfo(object):
Version = attr.ib(default=None) # Mandatory for Deadline
SaveFile = attr.ib(default=True)
IgnoreInputs = attr.ib(default=True)
Camera = attr.ib(default=None)


class MaxSubmitDeadline(abstract_submit_deadline.AbstractSubmitDeadline,
Expand Down Expand Up @@ -154,7 +155,8 @@ def get_plugin_info(self):
SceneFile=self.scene_path,
Version=instance.data["maxversion"],
SaveFile=True,
IgnoreInputs=True
IgnoreInputs=True,
Camera=instance.data["cameras"][0]
moonyuet marked this conversation as resolved.
Show resolved Hide resolved
)

plugin_payload = attr.asdict(plugin_info)
Expand Down Expand Up @@ -238,7 +240,9 @@ def _use_published_name(self, data, project_settings):
if renderer == "Redshift_Renderer":
plugin_data["redshift_SeparateAovFiles"] = instance.data.get(
"separateAovFiles")

if instance.data["cameras"]:
plugin_info["Camera0"] = None
plugin_info["Camera1"] = instance.data["cameras"][0]
self.log.debug("plugin data:{}".format(plugin_data))
plugin_info.update(plugin_data)

Expand Down