From a8eec8ae4f4807cce20f81dc68a948f31c49e744 Mon Sep 17 00:00:00 2001 From: BenoitConnan Date: Tue, 2 Nov 2021 15:02:47 +0100 Subject: [PATCH] Validate mesh ngons --- .../plugins/publish/validate_mesh_ngons.py | 54 +++++++++++++++++++ .../defaults/project_settings/maya.json | 5 ++ .../schemas/schema_maya_publish.json | 4 ++ 3 files changed, 63 insertions(+) create mode 100644 openpype/hosts/maya/plugins/publish/validate_mesh_ngons.py diff --git a/openpype/hosts/maya/plugins/publish/validate_mesh_ngons.py b/openpype/hosts/maya/plugins/publish/validate_mesh_ngons.py new file mode 100644 index 0000000000..3a5e2c05ae --- /dev/null +++ b/openpype/hosts/maya/plugins/publish/validate_mesh_ngons.py @@ -0,0 +1,54 @@ +from maya import cmds, mel + +import pyblish.api +import openpype.api +import openpype.hosts.maya.api.action +from avalon import maya +from openpype.hosts.maya.api import lib + +def polyConstraint(objects, *args, **kwargs): + #Using mode 3 to apply constraint on selected objects instead of selected faces. + kwargs.pop('mode', None) + + with lib.no_undo(flush=False): + with maya.maintained_selection(): + with lib.reset_polySelectConstraint(): + cmds.select(objects, r=1, noExpand=True) + # Acting as 'polyCleanupArgList' procedure for n-sided polygons selection + cmds.polySelectConstraint(*args, mode=3, **kwargs) + result = cmds.ls(selection=True) + cmds.select(clear=True) + + return result + + +class ValidateMeshNgons(pyblish.api.Validator): + """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 = openpype.api.ValidateContentsOrder + hosts = ["maya"] + families = ["model"] + label = "Mesh ngons" + actions = [openpype.hosts.maya.api.action.SelectInvalidAction] + + @staticmethod + def get_invalid(instance): + + meshes = cmds.ls(instance, type='mesh') + return polyConstraint(meshes, type=8, size=3) + + + def process(self, instance): + """Process all the nodes in the instance "objectSet""" + + invalid = self.get_invalid(instance) + if invalid: + raise ValueError("Meshes found with n-gons" + "values: {0}".format(invalid)) diff --git a/openpype/settings/defaults/project_settings/maya.json b/openpype/settings/defaults/project_settings/maya.json index f8f3432d0f..705917a9f4 100644 --- a/openpype/settings/defaults/project_settings/maya.json +++ b/openpype/settings/defaults/project_settings/maya.json @@ -255,6 +255,11 @@ "optional": true, "active": true }, + "ValidateMeshNgons": { + "enabled": false, + "optional": true, + "active": true + }, "ValidateMeshNonManifold": { "enabled": false, "optional": true, diff --git a/openpype/settings/entities/schemas/projects_schema/schemas/schema_maya_publish.json b/openpype/settings/entities/schemas/projects_schema/schemas/schema_maya_publish.json index cbacd12efa..58fe4cc4b1 100644 --- a/openpype/settings/entities/schemas/projects_schema/schemas/schema_maya_publish.json +++ b/openpype/settings/entities/schemas/projects_schema/schemas/schema_maya_publish.json @@ -274,6 +274,10 @@ "key": "ValidateMeshLaminaFaces", "label": "ValidateMeshLaminaFaces" }, + { + "key": "ValidateMeshNgons", + "label": "ValidateMeshNgons" + }, { "key": "ValidateMeshNonManifold", "label": "ValidateMeshNonManifold"