Skip to content

validate_scene_review

ValidateSceneReview

Bases: HoudiniInstancePlugin

Validator Some Scene Settings before publishing the review 1. Scene Path 2. Resolution

Source code in client/ayon_houdini/plugins/publish/validate_scene_review.py
10
11
12
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
class ValidateSceneReview(plugin.HoudiniInstancePlugin):
    """Validator Some Scene Settings before publishing the review
    1. Scene Path
    2. Resolution
    """

    order = pyblish.api.ValidatorOrder
    families = ["rop.opengl"]
    label = "Scene Setting for review"

    def process(self, instance):

        report = []
        instance_node = hou.node(instance.data.get("instance_node"))

        invalid = self.get_invalid_scene_path(instance_node)
        if invalid:
            report.append(invalid)

        invalid = self.get_invalid_camera_path(instance_node)
        if invalid:
            report.append(invalid)

        invalid = self.get_invalid_resolution(instance_node)
        if invalid:
            report.extend(invalid)

        if report:
            raise PublishValidationError("\n\n".join(report), title=self.label)

    def get_invalid_scene_path(self, rop_node):
        scene_path_parm = rop_node.parm("scenepath")
        scene_path_node = scene_path_parm.evalAsNode()
        if not scene_path_node:
            path = scene_path_parm.evalAsString()
            return "Scene path does not exist: '{}'".format(path)

    def get_invalid_camera_path(self, rop_node):

        import pxr

        opsource = rop_node.parm("opsource").eval()

        if opsource == 0:
            # Object-level
            camera_path_parm = rop_node.parm("camera")
            camera_node = camera_path_parm.evalAsNode()
            path = camera_path_parm.evalAsString()
            if not camera_node:
                return "Camera path does not exist: '{}'".format(path)
            type_name = camera_node.type().name()
            if type_name not in {"cam", "lopimportcam"}:
                return "Camera path is not a camera: '{}' (type: {})".format(
                    path, type_name
                )
        elif opsource == 1:
            # LOP-level
            lop_path = rop_node.parm("loppath").evalAsString()
            camera_path = rop_node.parm("cameraprim").evalAsString()

            stage = hou.node(lop_path).stage()
            camera_prim = stage.GetPrimAtPath(camera_path)

            if not camera_prim or not camera_prim.IsValid():
                return f"Camera prim path does not exist: '{camera_path}'"

            if not camera_prim.IsA(pxr.UsdGeom.Camera):
                return f"Camera path '{camera_path}' is not a camera."

        else:
            return "Unsupported camera source type: {}".format(opsource)

    def get_invalid_resolution(self, rop_node):

        # The resolution setting is only used when Override Camera Resolution
        # is enabled. So we skip validation if it is disabled.
        override = rop_node.parm("tres").eval()
        if not override:
            return

        invalid = []
        res_width = rop_node.parm("res1").eval()
        res_height = rop_node.parm("res2").eval()
        if res_width == 0:
            invalid.append("Override Resolution width is set to zero.")
        if res_height == 0:
            invalid.append("Override Resolution height is set to zero")

        return invalid