Skip to content

validate_look_sets

ValidateLookSets

Bases: MayaInstancePlugin

Validate if any sets relationships are not being collected.

Usually this collection fails if either the geometry or the shader are lacking a valid cbId attribute.

If the relationship needs to be maintained you may need to create a different* relationship or ensure the node has the cbId.

*The relationship might be too broad (assigned to top node of hierarchy). This can be countered by creating the relationship on the shape or its transform. In essence, ensure the node the shader is assigned to has a cbId.

For example:

Displacement objectSets (like V-Ray):

It is best practice to add the transform of the shape to the displacement objectSet. Any parent groups will not work as groups do not receive a cbId. As such the assignments need to be made to the shapes or their transform.

Source code in client/ayon_maya/plugins/publish/validate_look_sets.py
 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
 99
100
101
102
103
104
105
class ValidateLookSets(plugin.MayaInstancePlugin):
    """Validate if any sets relationships are not being collected.

    Usually this collection fails if either the geometry or the shader are
    lacking a valid `cbId` attribute.

    If the relationship needs to be maintained you may need to
    create a *different** relationship or ensure the node has the `cbId`.

    **The relationship might be too broad (assigned to top node of hierarchy).
    This can be countered by creating the relationship on the shape or its
    transform. In essence, ensure the node the shader is assigned to has a
    `cbId`.*

    ### For example:

    Displacement objectSets (like V-Ray):

    It is best practice to add the transform of the shape to the
    displacement objectSet. Any parent groups will not work as groups
    do not receive a `cbId`. As such the assignments need to be
    made to the shapes or their transform.

    """

    order = ValidateContentsOrder
    families = ['look']
    label = 'Look Sets'
    actions = [ayon_maya.api.action.SelectInvalidAction]

    def process(self, instance):
        """Process all the nodes in the instance"""

        invalid = self.get_invalid(instance)
        if invalid:
            raise PublishValidationError(
                f"'{instance.name}' has relationships that could not be "
                f"collected, likely due to lack of a `cbId` on the relevant "
                f"nodes or sets.",
                description=self.get_description())

    @classmethod
    def get_invalid(cls, instance):
        """Get all invalid nodes"""

        relationships = instance.data["lookData"]["relationships"]
        invalid = []

        renderlayer = instance.data.get("renderlayer", "defaultRenderLayer")
        with lib.renderlayer(renderlayer):
            for node in instance:
                # get the connected objectSets of the node
                sets = lib.get_related_sets(node)
                if not sets:
                    continue

                # check if any objectSets are not present in the relationships
                missing_sets = [s for s in sets if s not in relationships]
                # We ignore sets with `_SET` for legacy reasons but unclear why
                # TODO: should we remove this exclusion?
                missing_sets = [s for s in missing_sets if '_SET' not in s]
                if missing_sets:
                    for missing_set in missing_sets:
                        cls.log.debug(missing_set)

                    # A set of this node is not coming along.
                    cls.log.error("Missing sets for node '{}':\n - {}".format(
                        node, "\n - ".join(missing_sets)
                    ))
                    invalid.append(node)
                    continue

                # Ensure the node is in the sets that are collected
                for shader_set, data in relationships.items():
                    if shader_set not in sets:
                        # no need to check for a set if the node
                        # isn't in it anyway
                        continue

                    member_nodes = [member['name'] for member in
                                    data['members']]
                    if node not in member_nodes:
                        # The node is not found in the collected set
                        # relationships
                        cls.log.error("Missing '{}' in collected set node "
                                      "'{}'".format(node, shader_set))
                        invalid.append(node)
                        continue

        return invalid

    @classmethod
    def get_description(cls):
        return """## Missing look sets\n""" + inspect.getdoc(cls)

get_invalid(instance) classmethod

Get all invalid nodes

Source code in client/ayon_maya/plugins/publish/validate_look_sets.py
 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
@classmethod
def get_invalid(cls, instance):
    """Get all invalid nodes"""

    relationships = instance.data["lookData"]["relationships"]
    invalid = []

    renderlayer = instance.data.get("renderlayer", "defaultRenderLayer")
    with lib.renderlayer(renderlayer):
        for node in instance:
            # get the connected objectSets of the node
            sets = lib.get_related_sets(node)
            if not sets:
                continue

            # check if any objectSets are not present in the relationships
            missing_sets = [s for s in sets if s not in relationships]
            # We ignore sets with `_SET` for legacy reasons but unclear why
            # TODO: should we remove this exclusion?
            missing_sets = [s for s in missing_sets if '_SET' not in s]
            if missing_sets:
                for missing_set in missing_sets:
                    cls.log.debug(missing_set)

                # A set of this node is not coming along.
                cls.log.error("Missing sets for node '{}':\n - {}".format(
                    node, "\n - ".join(missing_sets)
                ))
                invalid.append(node)
                continue

            # Ensure the node is in the sets that are collected
            for shader_set, data in relationships.items():
                if shader_set not in sets:
                    # no need to check for a set if the node
                    # isn't in it anyway
                    continue

                member_nodes = [member['name'] for member in
                                data['members']]
                if node not in member_nodes:
                    # The node is not found in the collected set
                    # relationships
                    cls.log.error("Missing '{}' in collected set node "
                                  "'{}'".format(node, shader_set))
                    invalid.append(node)
                    continue

    return invalid

process(instance)

Process all the nodes in the instance

Source code in client/ayon_maya/plugins/publish/validate_look_sets.py
42
43
44
45
46
47
48
49
50
51
def process(self, instance):
    """Process all the nodes in the instance"""

    invalid = self.get_invalid(instance)
    if invalid:
        raise PublishValidationError(
            f"'{instance.name}' has relationships that could not be "
            f"collected, likely due to lack of a `cbId` on the relevant "
            f"nodes or sets.",
            description=self.get_description())