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: Implementation of the validator for model name #59

Merged
merged 26 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
45bb933
implement validator for model name in 3dsmax
moonyuet Jan 25, 2024
05e7c66
Merge branch 'develop' into enhancement/OP-7076_Validate-Model-Name
moonyuet Jan 29, 2024
1d83c6a
add validate model name settings for ayon
moonyuet Jan 29, 2024
43aadb2
resolve hound
moonyuet Jan 29, 2024
b822dd0
add docstring
moonyuet Jan 29, 2024
5e8af09
update regex name
moonyuet Jan 29, 2024
0e33857
Merge branch 'develop' into enhancement/OP-7076_Validate-Model-Name
moonyuet Feb 2, 2024
6b9da9b
update docstring
moonyuet Feb 2, 2024
12f78b1
update regex in ayon settings
moonyuet Feb 5, 2024
8ee2d8c
Merge branch 'develop' into enhancement/OP-7076_Validate-Model-Name
moonyuet Feb 5, 2024
09342f5
fix action.py
moonyuet Feb 5, 2024
1a63065
fix action.py
moonyuet Feb 5, 2024
bfd9520
hound
moonyuet Feb 5, 2024
05b9743
fix Libor's mentioned bug on action.py
moonyuet Feb 8, 2024
c9db644
hound shut
moonyuet Feb 8, 2024
19461e5
ported Validate Model Name from OP to ayon_core
moonyuet Feb 14, 2024
4a85b2e
bug fix the action.py
moonyuet Feb 21, 2024
1d07c2f
Merge branch 'develop' into enhancement/OP-7076_Validate-Model-Name
moonyuet Feb 21, 2024
c25161d
coverting asset to folderPath
moonyuet Feb 22, 2024
6f8e797
resolve conflict
moonyuet Feb 23, 2024
e5f5925
Merge branch 'develop' into enhancement/OP-7076_Validate-Model-Name
LiborBatek Feb 26, 2024
ff904e3
resolve conflict
moonyuet Feb 27, 2024
ff05252
Merge branch 'develop' into enhancement/OP-7076_Validate-Model-Name
LiborBatek Feb 28, 2024
fadf820
improve the code and the error message & docstring
moonyuet Feb 28, 2024
91a7c37
resolve conflict
moonyuet Mar 5, 2024
d35d719
Merge branch 'develop' into enhancement/OP-7076_Validate-Model-Name
moonyuet Mar 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions client/ayon_core/hosts/max/plugins/publish/validate_model_name.py
moonyuet marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# -*- coding: utf-8 -*-
"""Validate model nodes names."""
import re

import pyblish.api
from pymxs import runtime as rt

from ayon_core.hosts.max.api.action import SelectInvalidAction

from ayon_core.pipeline.publish import (
OptionalPyblishPluginMixin,
PublishValidationError,
ValidateContentsOrder)


class ValidateModelName(pyblish.api.InstancePlugin,
OptionalPyblishPluginMixin):
"""Validate Model Name
Validation regex is (.*)_(?P<subset>.*)_(GEO) by default.
e.g. {SOME_RANDOM_NAME}_{YOUR_SUBSET_NAME}_GEO should be your
default model name

The regex of (?P<subset>.*) can be replaced by (?P<asset>.*)
and (?P<project>.*).
e.g.
- (.*)_(?P<asset>.*)_(GEO) check if your model name is
{SOME_RANDOM_NAME}_{CURRENT_ASSET_NAME}_GEO
- (.*)_(?P<project>.*)_(GEO) check if your model name is
{SOME_RANDOM_NAME}_{CURRENT_PROJECT_NAME}_GEO

"""
moonyuet marked this conversation as resolved.
Show resolved Hide resolved
optional = True
order = ValidateContentsOrder
hosts = ["max"]
families = ["model"]
label = "Validate Model Name"
actions = [SelectInvalidAction]
regex = ""

@classmethod
def get_invalid(cls, instance):
invalid = []
model_names = [model.name for model in instance.data.get("members")]
cls.log.debug(model_names)
if not model_names:
cls.log.error("No Model found in the OP Data.")
moonyuet marked this conversation as resolved.
Show resolved Hide resolved
invalid.append(model_names)
for name in model_names:
invalid_model_name = cls.get_invalid_model_name(instance, name)
invalid.extend(invalid_model_name)

return invalid

@classmethod
def get_invalid_model_name(cls, instance, name):
invalid = []
regex = cls.regex
reg = re.compile(regex)
matched_name = reg.match(name)
project_name = instance.context.data["projectName"]
current_asset_name = instance.context.data["folderPath"]
if matched_name is None:
cls.log.error("invalid model name on: {}".format(name))
cls.log.error("name doesn't match regex {}".format(regex))
invalid.append((rt.getNodeByName(name),
"Model name doesn't match regex"))
else:
if "asset" in reg.groupindex:
if matched_name.group("asset") != current_asset_name:
cls.log.error(
"Invalid asset name of the model {}.".format(name)
)
invalid.append((rt.getNodeByName(name),
"Model with invalid asset name"))
if "subset" in reg.groupindex:
if matched_name.group("subset") != instance.name:
moonyuet marked this conversation as resolved.
Show resolved Hide resolved
cls.log.error(
"Invalid subset name of the model {}.".format(name)
)
invalid.append((rt.getNodeByName(name),
"Model with invalid subset name"))
if "project" in reg.groupindex:
if matched_name.group("project") != project_name:
cls.log.error(
"Invalid project name of the model {}.".format(name)
)
invalid.append((rt.getNodeByName(name),
"Model with invalid project name"))
return invalid

def process(self, instance):
if not self.is_active(instance.data):
self.log.debug("Skipping Validate Model Name...")
return

invalid = self.get_invalid(instance)

if invalid:
raise PublishValidationError(
"Model naming is invalid. See the log.")
106 changes: 106 additions & 0 deletions client/ayon_core/settings/defaults/project_settings/max.json
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this shouldn't probably be here in this PR

Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{
"unit_scale_settings": {
"enabled": true,
"scene_unit_scale": "Meters"
},
"imageio": {
"activate_host_color_management": true,
"ocio_config": {
"override_global_config": false,
"filepath": []
},
"file_rules": {
"activate_host_rules": false,
"rules": {}
}
},
"RenderSettings": {
"default_render_image_folder": "renders/3dsmax",
"aov_separator": "underscore",
"image_format": "exr",
"multipass": true
},
"CreateReview": {
"review_width": 1920,
"review_height": 1080,
"percentSize": 100.0,
"keep_images": false,
"image_format": "png",
"visual_style": "Realistic",
"viewport_preset": "Quality",
"anti_aliasing": "None",
"vp_texture": true
},
"PointCloud": {
"attribute": {
"Age": "age",
"Radius": "radius",
"Position": "position",
"Rotation": "rotation",
"Scale": "scale",
"Velocity": "velocity",
"Color": "color",
"TextureCoordinate": "texcoord",
"MaterialID": "matid",
"custFloats": "custFloats",
"custVecs": "custVecs"
}
},
"publish": {
"ValidateFrameRange": {
"enabled": true,
"optional": true,
"active": true
},
"ValidateAttributes": {
"enabled": false,
"attributes": {}
},
"ValidateCameraAttributes": {
"enabled": true,
"optional": true,
"active": false,
"fov": 45.0,
"nearrange": 0.0,
"farrange": 1000.0,
"nearclip": 1.0,
"farclip": 1000.0
},
"ValidateModelName": {
"enabled": true,
"optional": true,
"active": false,
"regex": "(.*)_(?P<subset>.*)_(GEO)"
},
"ValidateLoadedPlugin": {
"enabled": false,
"optional": true,
"family_plugins_mapping": []
},
"ExtractModelObj": {
"enabled": true,
"optional": true,
"active": false
},
"ExtractModelFbx": {
"enabled": true,
"optional": true,
"active": false
},
"ExtractModelUSD": {
"enabled": true,
"optional": true,
"active": false
},
"ExtractModel": {
"enabled": true,
"optional": true,
"active": true
},
"ExtractMaxSceneRaw": {
"enabled": true,
"optional": true,
"active": true
}
}
}
24 changes: 24 additions & 0 deletions server_addon/max/server/settings/publishers.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ class FamilyMappingItemModel(BaseSettingsModel):
)


class ValidateModelNameModel(BaseSettingsModel):
enabled: bool = SettingsField(title="Enabled")
optional: bool = SettingsField(title="Optional")
active: bool = SettingsField(title="Active")
regex: str = SettingsField(
"(.*)_(?P<subset>.*)_(GEO)",
title="Validation regex",
description=(
"Regex for validating model name. You can use named "
" capturing groups:(?P<asset>.*) for Asset name"
)
)


class ValidateLoadedPluginModel(BaseSettingsModel):
enabled: bool = SettingsField(title="Enabled")
optional: bool = SettingsField(title="Optional")
Expand Down Expand Up @@ -86,6 +100,10 @@ class PublishersModel(BaseSettingsModel):
default_factory=ValidateLoadedPluginModel,
title="Validate Loaded Plugin"
)
ValidateModelName: ValidateModelNameModel = SettingsField(
default_factory=ValidateModelNameModel,
title="Validate Model Name"
)
ExtractModelObj: BasicValidateModel = SettingsField(
default_factory=BasicValidateModel,
title="Extract OBJ",
Expand Down Expand Up @@ -129,6 +147,12 @@ class PublishersModel(BaseSettingsModel):
"nearclip": 1.0,
"farclip": 1000.0
},
"ValidateModelName": {
"enabled": True,
"optional": True,
"active": False,
"regex": "(.*)_(?P<subset>.*)_(GEO)"
},
"ValidateLoadedPlugin": {
"enabled": False,
"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"
Loading