Skip to content

validate_mesh_single_uv_set

ValidateMeshSingleUVSet

Bases: MayaInstancePlugin, OptionalPyblishPluginMixin

Warn on multiple UV sets existing for each polygon mesh.

On versions prior to Maya 2017 this will force no multiple uv sets because the Alembic exports in Maya prior to 2017 don't support writing multiple UV sets.

Source code in client/ayon_maya/plugins/publish/validate_mesh_single_uv_set.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
class ValidateMeshSingleUVSet(plugin.MayaInstancePlugin,
                              OptionalPyblishPluginMixin):
    """Warn on multiple UV sets existing for each polygon mesh.

    On versions prior to Maya 2017 this will force no multiple uv sets because
    the Alembic exports in Maya prior to 2017 don't support writing multiple
    UV sets.

    """

    order = ValidateMeshOrder
    families = ['model', 'pointcache']
    optional = True
    label = "Mesh Single UV Set"
    actions = [ayon_maya.api.action.SelectInvalidAction,
               RepairAction]

    @staticmethod
    def get_invalid(instance):

        meshes = cmds.ls(instance, type='mesh', long=True)

        invalid = []
        for mesh in meshes:
            uvSets = cmds.polyUVSet(mesh,
                                    query=True,
                                    allUVSets=True) or []

            # ensure unique (sometimes maya will list 'map1' twice)
            uvSets = set(uvSets)

            if len(uvSets) != 1:
                invalid.append(mesh)

        return invalid

    def process(self, instance):
        """Process all the nodes in the instance 'objectSet'"""
        if not self.is_active(instance.data):
            return

        invalid = self.get_invalid(instance)

        if invalid:

            message = "Nodes found with multiple UV sets: {0}".format(invalid)

            # Maya 2017 and up allows multiple UV sets in Alembic exports
            # so we allow it, yet just warn the user to ensure they know about
            # the other UV sets.
            allowed = int(cmds.about(version=True)) >= 2017

            if allowed:
                self.log.warning(message)
            else:
                raise PublishValidationError(message)

    @classmethod
    def repair(cls, instance):
        for mesh in cls.get_invalid(instance):
            lib.remove_other_uv_sets(mesh)

process(instance)

Process all the nodes in the instance 'objectSet'

Source code in client/ayon_maya/plugins/publish/validate_mesh_single_uv_set.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
def process(self, instance):
    """Process all the nodes in the instance 'objectSet'"""
    if not self.is_active(instance.data):
        return

    invalid = self.get_invalid(instance)

    if invalid:

        message = "Nodes found with multiple UV sets: {0}".format(invalid)

        # Maya 2017 and up allows multiple UV sets in Alembic exports
        # so we allow it, yet just warn the user to ensure they know about
        # the other UV sets.
        allowed = int(cmds.about(version=True)) >= 2017

        if allowed:
            self.log.warning(message)
        else:
            raise PublishValidationError(message)