mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
Merge pull request #267 from BigRoy/enhancement/maya_validate_model_content
Maya: Validate Model Content improve validation message
This commit is contained in:
commit
f08257bfbd
1 changed files with 47 additions and 15 deletions
|
|
@ -1,3 +1,5 @@
|
|||
import inspect
|
||||
|
||||
from maya import cmds
|
||||
|
||||
import pyblish.api
|
||||
|
|
@ -14,8 +16,7 @@ class ValidateModelContent(pyblish.api.InstancePlugin,
|
|||
OptionalPyblishPluginMixin):
|
||||
"""Adheres to the content of 'model' product type
|
||||
|
||||
- Must have one top group. (configurable)
|
||||
- Must only contain: transforms, meshes and groups
|
||||
See `get_description` for more details.
|
||||
|
||||
"""
|
||||
|
||||
|
|
@ -28,13 +29,16 @@ class ValidateModelContent(pyblish.api.InstancePlugin,
|
|||
validate_top_group = True
|
||||
optional = False
|
||||
|
||||
allowed = ('mesh', 'transform', 'nurbsCurve', 'nurbsSurface', 'locator')
|
||||
|
||||
@classmethod
|
||||
def get_invalid(cls, instance):
|
||||
|
||||
content_instance = instance.data.get("setMembers", None)
|
||||
if not content_instance:
|
||||
cls.log.error("Instance has no nodes!")
|
||||
return [instance.data["name"]]
|
||||
cls.log.error("Model instance has no nodes. "
|
||||
"It is not allowed to be empty")
|
||||
return [instance.data["instance_node"]]
|
||||
|
||||
# All children will be included in the extracted export so we also
|
||||
# validate *all* descendents of the set members and we skip any
|
||||
|
|
@ -46,30 +50,42 @@ class ValidateModelContent(pyblish.api.InstancePlugin,
|
|||
content_instance = list(set(content_instance + descendants))
|
||||
|
||||
# Ensure only valid node types
|
||||
allowed = ('mesh', 'transform', 'nurbsCurve', 'nurbsSurface', 'locator')
|
||||
nodes = cmds.ls(content_instance, long=True)
|
||||
valid = cmds.ls(content_instance, long=True, type=allowed)
|
||||
valid = cmds.ls(content_instance, long=True, type=cls.allowed)
|
||||
invalid = set(nodes) - set(valid)
|
||||
|
||||
if invalid:
|
||||
cls.log.error("These nodes are not allowed: %s" % invalid)
|
||||
# List as bullet points
|
||||
invalid_bullets = "\n".join(f"- {node}" for node in invalid)
|
||||
|
||||
cls.log.error(
|
||||
"These nodes are not allowed:\n{}\n\n"
|
||||
"The valid node types are: {}".format(
|
||||
invalid_bullets, ", ".join(cls.allowed))
|
||||
)
|
||||
return list(invalid)
|
||||
|
||||
if not valid:
|
||||
cls.log.error("No valid nodes in the instance")
|
||||
return True
|
||||
cls.log.error(
|
||||
"No valid nodes in the model instance.\n"
|
||||
"The valid node types are: {}".format(", ".join(cls.allowed))
|
||||
)
|
||||
return [instance.data["instance_node"]]
|
||||
|
||||
# Ensure it has shapes
|
||||
shapes = cmds.ls(valid, long=True, shapes=True)
|
||||
if not shapes:
|
||||
cls.log.error("No shapes in the model instance")
|
||||
return True
|
||||
return [instance.data["instance_node"]]
|
||||
|
||||
# Top group
|
||||
top_parents = set([x.split("|")[1] for x in content_instance])
|
||||
# Ensure single top group
|
||||
top_parents = {x.split("|", 2)[1] for x in content_instance}
|
||||
if cls.validate_top_group and len(top_parents) != 1:
|
||||
cls.log.error("Must have exactly one top group")
|
||||
return top_parents
|
||||
cls.log.error(
|
||||
"A model instance must have exactly one top group. "
|
||||
"Found top groups: {}".format(", ".join(top_parents))
|
||||
)
|
||||
return list(top_parents)
|
||||
|
||||
def _is_visible(node):
|
||||
"""Return whether node is visible"""
|
||||
|
|
@ -101,5 +117,21 @@ class ValidateModelContent(pyblish.api.InstancePlugin,
|
|||
if invalid:
|
||||
raise PublishValidationError(
|
||||
title="Model content is invalid",
|
||||
message="See log for more details"
|
||||
message="Model content is invalid. See log for more details.",
|
||||
description=self.get_description()
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def get_description(cls):
|
||||
return inspect.cleandoc(f"""
|
||||
### Model content is invalid
|
||||
|
||||
Your model instance does not adhere to the rules of a
|
||||
model product type:
|
||||
|
||||
- Must have at least one visible shape in it, like a mesh.
|
||||
- Must have one root node. When exporting multiple meshes they
|
||||
must be inside a group.
|
||||
- May only contain the following node types:
|
||||
{", ".join(cls.allowed)}
|
||||
""")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue