Skip to content

validate_mesh_ngons

ValidateMeshNgons

Bases: MayaInstancePlugin, OptionalPyblishPluginMixin

Ensure that meshes don't have ngons

Ngon are faces with more than 4 sides.

To debug the problem on the meshes you can use Maya's modeling tool: "Mesh > Cleanup..."

Source code in client/ayon_maya/plugins/publish/validate_mesh_ngons.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
class ValidateMeshNgons(plugin.MayaInstancePlugin,
                        OptionalPyblishPluginMixin):
    """Ensure that meshes don't have ngons

    Ngon are faces with more than 4 sides.

    To debug the problem on the meshes you can use Maya's modeling
    tool: "Mesh > Cleanup..."

    """

    order = ValidateContentsOrder
    families = ["model"]
    label = "Mesh ngons"
    actions = [ayon_maya.api.action.SelectInvalidAction]
    optional = True

    description = (
        "## Meshes with NGONs Faces\n"
        "Detected meshes with NGON faces. **NGONS** are faces that "
        "with more than four sides.\n\n"
        "### How to repair?\n"
        "You can repair them by usings Maya's modeling tool Mesh > Cleanup.. "
        "and select to cleanup matching polygons for lamina faces."
    )

    @staticmethod
    def get_invalid(instance):

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

        # Get all faces
        faces = ['{0}.f[*]'.format(node) for node in meshes]

        # Skip meshes that for some reason have no faces, e.g. empty meshes
        faces = cmds.ls(faces)
        if not faces:
            return []

        # Filter to n-sided polygon faces (ngons)
        invalid = lib.polyConstraint(faces,
                                     t=0x0008,  # type=face
                                     size=3)    # size=nsided

        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:
            raise PublishValidationError(
                "Meshes found with n-gons: {0}".format(invalid),
                description=self.description)

process(instance)

Process all the nodes in the instance "objectSet

Source code in client/ayon_maya/plugins/publish/validate_mesh_ngons.py
58
59
60
61
62
63
64
65
66
67
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:
        raise PublishValidationError(
            "Meshes found with n-gons: {0}".format(invalid),
            description=self.description)