Merge pull request #121 from ynput/enhancement/OP-7078_ValidateMeshHasUVs

Max: Validate Mesh Has UVs
This commit is contained in:
Kayla Man 2024-03-01 17:05:06 +08:00 committed by GitHub
commit 01bbf8ea1f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 68 additions and 1 deletions

View file

@ -0,0 +1,58 @@
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.
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
@classmethod
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 member.mesh.numTVerts == 0]
return invalid
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 = (
"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=(
"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")

View file

@ -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 @@ DEFAULT_PUBLISH_SETTINGS = {
"optional": True,
"family_plugins_mapping": []
},
"ValidateMeshHasUVs": {
"enabled": True,
"optional": True,
"active": False
},
"ExtractModelObj": {
"enabled": True,
"optional": True,

View file

@ -1 +1 @@
__version__ = "0.1.5"
__version__ = "0.1.6"