Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Max: Validate Mesh Has UVs #121

Merged
merged 14 commits into from
Mar 1, 2024
Merged
66 changes: 66 additions & 0 deletions client/ayon_core/hosts/max/plugins/publish/validate_mesh_has_uv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@

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
moonyuet marked this conversation as resolved.
Show resolved Hide resolved


class ValidateMeshHasUVs(pyblish.api.InstancePlugin,
OptionalPyblishPluginMixin):

"""Validate the current mesh has UVs.

This validator only checks if the mesh has UVs but not
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.

"""

order = ValidateMeshOrder
hosts = ['max']
families = ['model']
label = 'Validate Mesh Has UVs'
actions = [SelectInvalidAction]
optional = True


moonyuet marked this conversation as resolved.
Show resolved Hide resolved
@classmethod
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")
return invalid_mesh_type
moonyuet marked this conversation as resolved.
Show resolved Hide resolved

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

def process(self, instance):
invalid = self.get_invalid(instance)
if invalid:
bullet_point_invalid_statement = "\n".join(
"- {}".format(invalid.name) for invalid
in invalid
)
report = (
"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=(
"Non-mesh objects detected or the meshes do not have any UVs.\n\n"
"Meshes detected with no texture vertice or missing UVs"),
title="Non-mesh objects found or mesh has missing UVs")
9 changes: 9 additions & 0 deletions server_addon/max/server/settings/publishers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -134,6 +138,11 @@ class PublishersModel(BaseSettingsModel):
"optional": True,
"family_plugins_mapping": []
},
"ValidateMeshHasUVs": {
"enabled": True,
"optional": True,
"active": False
},
"ExtractModelObj": {
"enabled": True,
"optional": True,
Expand Down
2 changes: 1 addition & 1 deletion server_addon/max/server/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.5"
__version__ = "0.1.6"