Skip to content

validate_mesh_non_zero_edge

ValidateMeshNonZeroEdgeLength

Bases: MayaInstancePlugin, OptionalPyblishPluginMixin

Validate meshes don't have edges with a zero length.

Based on Maya's polyCleanup 'Edges with zero length'.

Note

This can be slow for high-res meshes.

Source code in client/ayon_maya/plugins/publish/validate_mesh_non_zero_edge.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
class ValidateMeshNonZeroEdgeLength(plugin.MayaInstancePlugin,
                                    OptionalPyblishPluginMixin):
    """Validate meshes don't have edges with a zero length.

    Based on Maya's polyCleanup 'Edges with zero length'.

    Note:
        This can be slow for high-res meshes.

    """

    order = ValidateMeshOrder
    families = ['model']
    label = 'Mesh Edge Length Non Zero'
    actions = [ayon_maya.api.action.SelectInvalidAction]
    optional = True

    __tolerance = 1e-5

    @classmethod
    def get_invalid(cls, instance):
        """Return the invalid edges.

        Also see:

        http://help.autodesk.com/view/MAYAUL/2015/ENU/?guid=Mesh__Cleanup

        """

        meshes = cmds.ls(instance, type='mesh', long=True)
        if not meshes:
            return list()

        valid_meshes = []
        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

            valid_meshes.append(mesh)

        # Get all edges
        edges = ['{0}.e[*]'.format(node) for node in valid_meshes]

        # Filter by constraint on edge length
        invalid = lib.polyConstraint(edges,
                                     t=0x8000,  # type=edge
                                     length=1,
                                     lengthbound=(0, cls.__tolerance))

        return invalid

    def process(self, instance):
        """Process all meshes"""
        if not self.is_active(instance.data):
            return

        invalid = self.get_invalid(instance)
        if invalid:
            label = "Meshes found with zero edge length"
            raise PublishValidationError(
                message="{}: {}".format(label, invalid),
                title=label,
                description="{}:\n- ".format(label) + "\n- ".join(invalid)
            )

get_invalid(instance) classmethod

Return the invalid edges.

Also see:

http://help.autodesk.com/view/MAYAUL/2015/ENU/?guid=Mesh__Cleanup

Source code in client/ayon_maya/plugins/publish/validate_mesh_non_zero_edge.py
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
@classmethod
def get_invalid(cls, instance):
    """Return the invalid edges.

    Also see:

    http://help.autodesk.com/view/MAYAUL/2015/ENU/?guid=Mesh__Cleanup

    """

    meshes = cmds.ls(instance, type='mesh', long=True)
    if not meshes:
        return list()

    valid_meshes = []
    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

        valid_meshes.append(mesh)

    # Get all edges
    edges = ['{0}.e[*]'.format(node) for node in valid_meshes]

    # Filter by constraint on edge length
    invalid = lib.polyConstraint(edges,
                                 t=0x8000,  # type=edge
                                 length=1,
                                 lengthbound=(0, cls.__tolerance))

    return invalid

process(instance)

Process all meshes

Source code in client/ayon_maya/plugins/publish/validate_mesh_non_zero_edge.py
69
70
71
72
73
74
75
76
77
78
79
80
81
def process(self, instance):
    """Process all meshes"""
    if not self.is_active(instance.data):
        return

    invalid = self.get_invalid(instance)
    if invalid:
        label = "Meshes found with zero edge length"
        raise PublishValidationError(
            message="{}: {}".format(label, invalid),
            title=label,
            description="{}:\n- ".format(label) + "\n- ".join(invalid)
        )