From 2c0cb76f35fb3530cc5762bbb61d1edbdba2b6e0 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Tue, 27 Feb 2024 17:39:30 +0800 Subject: [PATCH 01/10] validate the mesh has uv --- .../plugins/publish/validate_mesh_has_uv.py | 45 +++++++++++++++++++ .../max/server/settings/publishers.py | 9 ++++ server_addon/max/server/version.py | 2 +- 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py diff --git a/client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py b/client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py new file mode 100644 index 0000000000..3e966acc87 --- /dev/null +++ b/client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py @@ -0,0 +1,45 @@ + +import pyblish.api +from ayon_core.hosts.max.api.action import SelectInvalidAction +from ayon_core.pipeline.publish import ( + ValidateMeshOrder, + OptionalPyblishPluginMixin, + PublishValidationError +) +from pymxs import runtime as rt + + +class ValidateMeshHasUVs(pyblish.api.InstancePlugin, + OptionalPyblishPluginMixin): + + """Validate the current mesh has UVs. + + It validates whether the current UV set has non-zero UVs and + at least more than the vertex count. It's not really bulletproof, + but a simple quick validation to check if there are likely + UVs for every face. + """ + + order = ValidateMeshOrder + hosts = ['max'] + families = ['model'] + label = 'Validate Mesh Has UVs' + actions = [SelectInvalidAction] + optional = True + + + @classmethod + def get_invalid(cls, instance): + invalid = [member for member in instance.data["members"] + if not member.mesh.numTVerts > 0] + return invalid + + def process(self, instance): + invalid = self.get_invalid(instance) + if invalid: + raise PublishValidationError( + title="Mesh has missing UVs", + message="Model meshes are required to have UVs.

" + "Meshes detected with invalid or missing UVs:
" + "{0}".format(invalid) + ) diff --git a/server_addon/max/server/settings/publishers.py b/server_addon/max/server/settings/publishers.py index 5e28c1b467..6ea6a887d1 100644 --- a/server_addon/max/server/settings/publishers.py +++ b/server_addon/max/server/settings/publishers.py @@ -86,6 +86,10 @@ class PublishersModel(BaseSettingsModel): default_factory=ValidateLoadedPluginModel, title="Validate Loaded Plugin" ) + ValidateMeshHasUVs: BasicValidateModel = SettingsField( + default_factory=BasicValidateModel, + title="Validate Mesh Has UVs" + ) ExtractModelObj: BasicValidateModel = SettingsField( default_factory=BasicValidateModel, title="Extract OBJ", @@ -134,6 +138,11 @@ class PublishersModel(BaseSettingsModel): "optional": True, "family_plugins_mapping": [] }, + "ValidateMeshHasUVs": { + "enabled": True, + "optional": True, + "active": False + }, "ExtractModelObj": { "enabled": True, "optional": True, diff --git a/server_addon/max/server/version.py b/server_addon/max/server/version.py index 1276d0254f..0a8da88258 100644 --- a/server_addon/max/server/version.py +++ b/server_addon/max/server/version.py @@ -1 +1 @@ -__version__ = "0.1.5" +__version__ = "0.1.6" From d9a278e470af8f7542dd53e9f3c3976ccd6c3c00 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Tue, 27 Feb 2024 18:42:48 +0800 Subject: [PATCH 02/10] correct object name for the error message --- .../ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py b/client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py index 3e966acc87..a55b49b515 100644 --- a/client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py +++ b/client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py @@ -41,5 +41,5 @@ def process(self, instance): title="Mesh has missing UVs", message="Model meshes are required to have UVs.

" "Meshes detected with invalid or missing UVs:
" - "{0}".format(invalid) + "{0}".format([err.name for err in invalid]) ) From f3ee01ba72cf25c9c1a9f8c540521025312ff619 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Tue, 27 Feb 2024 18:53:27 +0800 Subject: [PATCH 03/10] edit docstring --- .../hosts/max/plugins/publish/validate_mesh_has_uv.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py b/client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py index a55b49b515..eda638daae 100644 --- a/client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py +++ b/client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py @@ -14,10 +14,9 @@ class ValidateMeshHasUVs(pyblish.api.InstancePlugin, """Validate the current mesh has UVs. - It validates whether the current UV set has non-zero UVs and - at least more than the vertex count. It's not really bulletproof, - but a simple quick validation to check if there are likely - UVs for every face. + It validates whether the current mesh has texture vertex(s). + If the mesh does not have texture vertex(s), it does not + have UVs in Max. """ order = ValidateMeshOrder From cd694266b8375e8b5e96974b869fe5360fcdf89c Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Tue, 27 Feb 2024 21:34:45 +0800 Subject: [PATCH 04/10] improve error message and docstring --- .../plugins/publish/validate_mesh_has_uv.py | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py b/client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py index eda638daae..4cef1a5658 100644 --- a/client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py +++ b/client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py @@ -14,9 +14,12 @@ class ValidateMeshHasUVs(pyblish.api.InstancePlugin, """Validate the current mesh has UVs. - It validates whether the current mesh has texture vertex(s). - If the mesh does not have texture vertex(s), it does not + This validator only checks if the mesh has UVs but not + whether the faces of the mesh have UVs. + It validates whether the current mesh has texture vertices. + If the mesh does not have texture vertices, it does not have UVs in Max. + """ order = ValidateMeshOrder @@ -36,9 +39,18 @@ def get_invalid(cls, instance): def process(self, instance): invalid = self.get_invalid(instance) if invalid: - raise PublishValidationError( - title="Mesh has missing UVs", - message="Model meshes are required to have UVs.

" - "Meshes detected with invalid or missing UVs:
" - "{0}".format([err.name for err in invalid]) + bullet_point_invalid_statement = "\n".join( + "- {}".format(invalid.name) for invalid + in invalid ) + report = ( + "Model meshes are required to have UVs.\n\n" + "Meshes detected with invalid or missing UVs:\n" + f"{bullet_point_invalid_statement}\n\n" + ) + raise PublishValidationError( + report, + description=( + "Model meshes are required to have UVs.\n\n" + "Meshes detected with no texture vertice(s) or missing UVs"), + title="Mesh has missing UVs") From 16b28fe3bd3956974550a55f31cdf073dd3c9c15 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Wed, 28 Feb 2024 17:54:19 +0800 Subject: [PATCH 05/10] tweak docstring --- .../hosts/max/plugins/publish/validate_mesh_has_uv.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py b/client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py index 4cef1a5658..846e537b69 100644 --- a/client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py +++ b/client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py @@ -15,7 +15,8 @@ class ValidateMeshHasUVs(pyblish.api.InstancePlugin, """Validate the current mesh has UVs. This validator only checks if the mesh has UVs but not - whether the faces of the mesh have UVs. + whether all the individual faces of the mesh have UVs. + It validates whether the current mesh has texture vertices. If the mesh does not have texture vertices, it does not have UVs in Max. @@ -52,5 +53,5 @@ def process(self, instance): report, description=( "Model meshes are required to have UVs.\n\n" - "Meshes detected with no texture vertice(s) or missing UVs"), + "Meshes detected with no texture vertice or missing UVs"), title="Mesh has missing UVs") From d98c055a048591168d64b3e0ec11243bbbf8bde6 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Wed, 28 Feb 2024 20:14:43 +0800 Subject: [PATCH 06/10] some tweaks on codes --- .../plugins/publish/validate_mesh_has_uv.py | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py b/client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py index 846e537b69..21339c1d41 100644 --- a/client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py +++ b/client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py @@ -33,9 +33,21 @@ class ValidateMeshHasUVs(pyblish.api.InstancePlugin, @classmethod def get_invalid(cls, instance): - invalid = [member for member in instance.data["members"] - if not member.mesh.numTVerts > 0] - return invalid + invalid_mesh_type = [member for member in instance.data["members"] + if not rt.isProperty(member, "mesh")] + if invalid_mesh_type: + cls.log.error("Non-mesh type objects detected:\n".join( + "-{}".format(invalid.name) for invalid + in invalid_mesh_type)) + return invalid_mesh_type + + invalid_uv = [member for member in instance.data["members"] + if not member.mesh.numTVerts > 0] + if invalid_uv: + cls.log.error("Meshes detected with invalid UVs:\n".join( + "-{}".format(invalid.name) for invalid + in invalid_uv)) + return invalid_uv def process(self, instance): invalid = self.get_invalid(instance) @@ -47,7 +59,7 @@ def process(self, instance): report = ( "Model meshes are required to have UVs.\n\n" "Meshes detected with invalid or missing UVs:\n" - f"{bullet_point_invalid_statement}\n\n" + f"{bullet_point_invalid_statement}\n" ) raise PublishValidationError( report, From 0e35253bdee1a0bdef553ab7b8d05823280de6f9 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Wed, 28 Feb 2024 20:44:33 +0800 Subject: [PATCH 07/10] add a check on non-mesh objects in the validator --- .../max/plugins/publish/validate_mesh_has_uv.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py b/client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py index 21339c1d41..5594a6a789 100644 --- a/client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py +++ b/client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py @@ -36,17 +36,13 @@ def get_invalid(cls, instance): invalid_mesh_type = [member for member in instance.data["members"] if not rt.isProperty(member, "mesh")] if invalid_mesh_type: - cls.log.error("Non-mesh type objects detected:\n".join( - "-{}".format(invalid.name) for invalid - in invalid_mesh_type)) + cls.log.error("Non-mesh type objects detected") return invalid_mesh_type invalid_uv = [member for member in instance.data["members"] if not member.mesh.numTVerts > 0] if invalid_uv: - cls.log.error("Meshes detected with invalid UVs:\n".join( - "-{}".format(invalid.name) for invalid - in invalid_uv)) + cls.log.error("Meshes detected with invalid UVs") return invalid_uv def process(self, instance): @@ -57,13 +53,14 @@ def process(self, instance): in invalid ) report = ( - "Model meshes are required to have UVs.\n\n" + "Non-mesh objects found or mesh objects" + " do not have UVs.\n\n" "Meshes detected with invalid or missing UVs:\n" f"{bullet_point_invalid_statement}\n" ) raise PublishValidationError( report, description=( - "Model meshes are required to have UVs.\n\n" + "Non-mesh objects detected or the meshes do not have any UVs.\n\n" "Meshes detected with no texture vertice or missing UVs"), - title="Mesh has missing UVs") + title="Non-mesh objects found or mesh has missing UVs") From 56f4f04d1c1b94b8afc41da66eaff99ba8c49bd6 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Thu, 29 Feb 2024 15:08:25 +0800 Subject: [PATCH 08/10] edit the code would pass only when the object is mesh type --- .../plugins/publish/validate_mesh_has_uv.py | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py b/client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py index 5594a6a789..4d1490ac8f 100644 --- a/client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py +++ b/client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py @@ -30,20 +30,17 @@ class ValidateMeshHasUVs(pyblish.api.InstancePlugin, actions = [SelectInvalidAction] optional = True - @classmethod def get_invalid(cls, instance): invalid_mesh_type = [member for member in instance.data["members"] - if not rt.isProperty(member, "mesh")] + if rt.isProperty(member, "mesh")] if invalid_mesh_type: - cls.log.error("Non-mesh type objects detected") - return invalid_mesh_type + invalid_uv = [member for member in instance.data["members"] + if not member.mesh.numTVerts > 0] + if invalid_uv: + cls.log.error("Meshes detected with invalid UVs") - invalid_uv = [member for member in instance.data["members"] - if not member.mesh.numTVerts > 0] - if invalid_uv: - cls.log.error("Meshes detected with invalid UVs") - return invalid_uv + return invalid_uv def process(self, instance): invalid = self.get_invalid(instance) @@ -53,14 +50,13 @@ def process(self, instance): in invalid ) report = ( - "Non-mesh objects found or mesh objects" - " do not have UVs.\n\n" + "Model meshes are required to have UVs.\n\n" "Meshes detected with invalid or missing UVs:\n" f"{bullet_point_invalid_statement}\n" ) raise PublishValidationError( report, description=( - "Non-mesh objects detected or the meshes do not have any UVs.\n\n" + "Model meshes are required to have UVs.\n\n" "Meshes detected with no texture vertice or missing UVs"), title="Non-mesh objects found or mesh has missing UVs") From c7ba4be69c9e46f02b05976ab8aec4514de5306c Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Thu, 29 Feb 2024 20:37:23 +0800 Subject: [PATCH 09/10] code clean up with bigroy's comment --- .../max/plugins/publish/validate_mesh_has_uv.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py b/client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py index 4d1490ac8f..cecc16c3c3 100644 --- a/client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py +++ b/client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py @@ -32,15 +32,11 @@ class ValidateMeshHasUVs(pyblish.api.InstancePlugin, @classmethod def get_invalid(cls, instance): - invalid_mesh_type = [member for member in instance.data["members"] - if rt.isProperty(member, "mesh")] - if invalid_mesh_type: - invalid_uv = [member for member in instance.data["members"] - if not member.mesh.numTVerts > 0] - if invalid_uv: - cls.log.error("Meshes detected with invalid UVs") - - return invalid_uv + meshes = [member for member in instance.data["members"] + if rt.isProperty(member, "mesh")] + invalid = [member for member in meshes + if not member.mesh.numTVerts > 0] + return invalid def process(self, instance): invalid = self.get_invalid(instance) From 1bdac65841bc92d77c7df5353d7d96b5ab9f8b2d Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Thu, 29 Feb 2024 20:43:13 +0800 Subject: [PATCH 10/10] code clean up --- .../ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py b/client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py index cecc16c3c3..109b7fe0b5 100644 --- a/client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py +++ b/client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py @@ -35,7 +35,7 @@ def get_invalid(cls, instance): meshes = [member for member in instance.data["members"] if rt.isProperty(member, "mesh")] invalid = [member for member in meshes - if not member.mesh.numTVerts > 0] + if member.mesh.numTVerts == 0] return invalid def process(self, instance):