Skip to content

validate_resolution

ValidateResolution

Bases: MayaInstancePlugin, OptionalPyblishPluginMixin

Validate the render resolution setting aligned with DB

Source code in client/ayon_maya/plugins/publish/validate_resolution.py
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
class ValidateResolution(plugin.MayaInstancePlugin,
                         OptionalPyblishPluginMixin):
    """Validate the render resolution setting aligned with DB"""

    order = pyblish.api.ValidatorOrder
    families = ["renderlayer"]
    label = "Validate Resolution"
    actions = [RepairAction]
    optional = True

    def process(self, instance):
        if not self.is_active(instance.data):
            return
        invalid = self.get_invalid_resolution(instance)
        if invalid:
            raise PublishValidationError(
                "Render resolution is invalid. See log for details.",
                description=(
                    "Wrong render resolution setting. "
                    "Please use repair button to fix it.\n\n"
                    "If current renderer is V-Ray, "
                    "make sure vraySettings node has been created."
                )
            )

    @classmethod
    def get_invalid_resolution(cls, instance):
        width, height, pixelAspect = cls.get_folder_resolution(instance)
        current_renderer = instance.data["renderer"]
        layer = instance.data["renderlayer"]
        invalid = False
        if current_renderer == "vray":
            vray_node = "vraySettings"
            if cmds.objExists(vray_node):
                current_width = lib.get_attr_in_layer(
                    "{}.width".format(vray_node), layer=layer)
                current_height = lib.get_attr_in_layer(
                    "{}.height".format(vray_node), layer=layer)
                current_pixelAspect = lib.get_attr_in_layer(
                    "{}.pixelAspect".format(vray_node), layer=layer
                )
            else:
                cls.log.error(
                    "Can't detect VRay resolution because there is no node "
                    "named: `{}`".format(vray_node)
                )
                return True
        else:
            current_width = lib.get_attr_in_layer(
                "defaultResolution.width", layer=layer)
            current_height = lib.get_attr_in_layer(
                "defaultResolution.height", layer=layer)
            current_pixelAspect = lib.get_attr_in_layer(
                "defaultResolution.pixelAspect", layer=layer
            )
        if current_width != width or current_height != height:
            cls.log.error(
                "Render resolution {}x{} does not match "
                "folder resolution {}x{}".format(
                    current_width, current_height,
                    width, height
                ))
            invalid = True
        if current_pixelAspect != pixelAspect:
            cls.log.error(
                "Render pixel aspect {} does not match "
                "folder pixel aspect {}".format(
                    current_pixelAspect, pixelAspect
                ))
            invalid = True
        return invalid

    @classmethod
    def get_folder_resolution(cls, instance):
        task_attributes = instance.data["taskEntity"]["attrib"]
        width = task_attributes["resolutionWidth"]
        height = task_attributes["resolutionHeight"]
        pixel_aspect = task_attributes["pixelAspect"]
        return int(width), int(height), float(pixel_aspect)

    @classmethod
    def repair(cls, instance):
        # Usually without renderlayer overrides the renderlayers
        # all share the same resolution value - so fixing the first
        # will have fixed all the others too. It's much faster to
        # check whether it's invalid first instead of switching
        # into all layers individually
        if not cls.get_invalid_resolution(instance):
            cls.log.debug(
                "Nothing to repair on instance: {}".format(instance)
            )
            return
        layer_node = instance.data['setMembers']
        with lib.renderlayer(layer_node):
            reset_scene_resolution()