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 8 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
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
48 changes: 48 additions & 0 deletions openpype/hosts/max/plugins/publish/validate_viewport_camera.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# -*- 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 ValidateViewportCamera(pyblish.api.InstancePlugin,
OptionalPyblishPluginMixin):
"""Validates Viewport Camera
moonyuet marked this conversation as resolved.
Show resolved Hide resolved

Check if the renderable camera in scene used as viewport
camera for rendering
moonyuet marked this conversation as resolved.
Show resolved Hide resolved
"""

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

def process(self, instance):
if not self.is_active(instance.data):
return
cameras_in_scene = [c for c in rt.Objects
if rt.classOf(c) in rt.Camera.Classes]
if rt.viewport.getCamera() not in cameras_in_scene:
raise PublishValidationError(
"Cameras in Scene not used as viewport camera"
)
moonyuet marked this conversation as resolved.
Show resolved Hide resolved

@classmethod
def repair(cls, instance):

rt.viewport.setType(rt.Name("view_camera"))
camera = rt.viewport.GetCamera()
cls.log.info(f"Camera {camera} set as viewport 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()