Skip to content

validate_mesh_vertices_have_edges

ValidateMeshVerticesHaveEdges

Bases: MayaInstancePlugin, OptionalPyblishPluginMixin

Validate meshes have only vertices that are connected to edges.

Maya can have invalid geometry with vertices that have no edges or faces connected to them.

In Maya 2016 EXT 2 and later there's a command to fix this: maya.cmds.polyClean(mesh, cleanVertices=True)

In older versions of Maya it works to select the invalid vertices and merge the components.

To find these invalid vertices select all vertices of the mesh that are visible in the viewport (drag to select), afterwards invert your selection (Ctrl + Shift + I). The remaining selection contains the invalid vertices.

Source code in client/ayon_maya/plugins/publish/validate_mesh_vertices_have_edges.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
class ValidateMeshVerticesHaveEdges(plugin.MayaInstancePlugin,
                                    OptionalPyblishPluginMixin):
    """Validate meshes have only vertices that are connected to edges.

    Maya can have invalid geometry with vertices that have no edges or
    faces connected to them.

    In Maya 2016 EXT 2 and later there's a command to fix this:
        `maya.cmds.polyClean(mesh, cleanVertices=True)`

    In older versions of Maya it works to select the invalid vertices
    and merge the components.

    To find these invalid vertices select all vertices of the mesh
    that are visible in the viewport (drag to select), afterwards
    invert your selection (Ctrl + Shift + I). The remaining selection
    contains the invalid vertices.

    """

    order = ValidateMeshOrder
    families = ['model']
    label = 'Mesh Vertices Have Edges'
    actions = [ayon_maya.api.action.SelectInvalidAction,
               RepairAction]
    optional = True

    @classmethod
    def repair(cls, instance):

        # This fix only works in Maya 2016 EXT2 and newer
        if float(cmds.about(version=True)) <= 2016.0:
            raise PublishValidationError(
                ("Repair not supported in Maya version below "
                 "2016 EXT 2"))

        invalid = cls.get_invalid(instance)
        for node in invalid:
            cmds.polyClean(node, cleanVertices=True)

    @classmethod
    def get_invalid(cls, instance):
        invalid = []

        meshes = cmds.ls(instance, type="mesh", long=True)
        for mesh in meshes:
            num_vertices = cmds.polyEvaluate(mesh, vertex=True)

            if num_vertices == 0:
                cls.log.warning(
                    "Skipping \"{}\", cause it does not have any "
                    "vertices.".format(mesh)
                )
                continue

            # Vertices from all edges
            edges = "%s.e[*]" % mesh
            vertices = cmds.polyListComponentConversion(edges, toVertex=True)
            num_vertices_from_edges = len_flattened(vertices)

            if num_vertices != num_vertices_from_edges:
                invalid.append(mesh)

        return invalid

    def process(self, instance):
        if not self.is_active(instance.data):
            return
        invalid = self.get_invalid(instance)
        if invalid:
            raise PublishValidationError(
                ("Meshes found in instance with vertices that "
                 "have no edges: {}").format(invalid))