From 6fb3cfafdd92b8c63187cd64912bd87f8ef19e54 Mon Sep 17 00:00:00 2001 From: Ondrej Samohel Date: Wed, 16 Dec 2020 18:44:04 +0100 Subject: [PATCH] repair action for validator, skip unwanted referenced aovs --- pype/hosts/maya/expected_files.py | 21 +++--- .../publish/validate_vray_referenced_aovs.py | 73 +++++++++++++++---- 2 files changed, 69 insertions(+), 25 deletions(-) diff --git a/pype/hosts/maya/expected_files.py b/pype/hosts/maya/expected_files.py index 9dd10e573e..07b3f94aa0 100644 --- a/pype/hosts/maya/expected_files.py +++ b/pype/hosts/maya/expected_files.py @@ -627,19 +627,20 @@ class ExpectedFilesVray(AExpectedFiles): if default_ext == "exr (multichannel)" or default_ext == "exr (deep)": default_ext = "exr" - # filter all namespace prefixed AOVs - they are pulled in from - # references. Or leave them alone, based on preferences on render - # instance. - ref_aovs = self.render_instance.data.get( + # handle aovs from references + use_ref_aovs = self.render_instance.data.get( "vrayUseReferencedAovs", False) or False - if ref_aovs: - vr_aovs = cmds.ls( - type=["VRayRenderElement", "VRayRenderElementSet"]) or [] - else: - vr_aovs = cmds.ls( + # this will have list of all aovs no matter if they are coming from + # reference or not. + vr_aovs = cmds.ls( + type=["VRayRenderElement", "VRayRenderElementSet"]) or [] + if not use_ref_aovs: + ref_aovs = cmds.ls( type=["VRayRenderElement", "VRayRenderElementSet"], - referencedNodes=False) or [] + referencedNodes=True) or [] + # get difference + vr_aovs = list(set(vr_aovs) - set(ref_aovs)) for aov in vr_aovs: enabled = self.maya_is_true(cmds.getAttr("{}.enabled".format(aov))) diff --git a/pype/plugins/maya/publish/validate_vray_referenced_aovs.py b/pype/plugins/maya/publish/validate_vray_referenced_aovs.py index 0c1a5f552a..67d5ed558c 100644 --- a/pype/plugins/maya/publish/validate_vray_referenced_aovs.py +++ b/pype/plugins/maya/publish/validate_vray_referenced_aovs.py @@ -1,8 +1,7 @@ # -*- coding: utf-8 -*- """Validate if there are AOVs pulled from references.""" import pyblish.api -import pype.api - +import types from maya import cmds import pype.hosts.maya.action @@ -21,7 +20,7 @@ class ValidateVrayReferencedAOVs(pyblish.api.InstancePlugin): label = 'VRay Referenced AOVs' hosts = ['maya'] families = ['renderlayer'] - actions = [pype.hosts.maya.action.SelectInvalidAction] + actions = [pype.api.RepairContextAction] def process(self, instance): """Plugin main entry point.""" @@ -29,21 +28,65 @@ class ValidateVrayReferencedAOVs(pyblish.api.InstancePlugin): # If not V-Ray ignore.. return + ref_aovs = cmds.ls( + type=["VRayRenderElement", "VRayRenderElementSet"], + referencedNodes=True) + ref_aovs_enabled = ValidateVrayReferencedAOVs.maya_is_true( + cmds.getAttr("vraySettings.relements_usereferenced")) + if not instance.data.get("vrayUseReferencedAovs"): - self.get_invalid(instance) + if ref_aovs_enabled and ref_aovs: + self.log.warning(( + "Referenced AOVs are enabled in Vray " + "Render Settings and are detected in scene, but " + "Pype render instance option for referenced AOVs is " + "disabled. Those AOVs will be rendered but not published " + "by Pype." + )) + self.log.warning(", ".join(ref_aovs)) + else: + if not ref_aovs: + self.log.warning(( + "Use of referenced AOVs enabled but there are none " + "in the scene." + )) + if not ref_aovs_enabled: + self.log.error(( + "'Use referenced' not enabled in Vray Render Settings." + )) + raise AssertionError("Invalid render settings") @classmethod - def get_invalid(cls, instance): - """Find referenced AOVs in scene.""" + def repair(cls, context): - if cmds.getAttr("vraySettings.relements_usereferenced") == 0: - ref_aovs = cmds.ls( - type=["VRayRenderElement", "VRayRenderElementSet"], - referencedNodes=True) or [] + vray_settings = cmds.ls(type="VRaySettingsNode") + if not vray_settings: + node = cmds.createNode("VRaySettingsNode") + else: + node = vray_settings[0] - if ref_aovs: - cls.log.warning( - "Scene contain referenced AOVs: {}".format(ref_aovs)) + cmds.setAttr("{}.relements_usereferenced".format(node), True) - # Return the instance itself - return ref_aovs + + + @staticmethod + def maya_is_true(attr_val): + """Whether a Maya attr evaluates to True. + + When querying an attribute value from an ambiguous object the + Maya API will return a list of values, which need to be properly + handled to evaluate properly. + + Args: + attr_val (mixed): Maya attribute to be evaluated as bool. + + Returns: + bool: cast Maya attribute to Pythons boolean value. + + """ + if isinstance(attr_val, types.BooleanType): + return attr_val + elif isinstance(attr_val, (types.ListType, types.GeneratorType)): + return any(attr_val) + else: + return bool(attr_val)