This repository has been archived by the owner on Sep 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6110 from ynput/enhancement/OP-7075_Validate-Came…
…ra-Attributes
- Loading branch information
Showing
6 changed files
with
240 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from pymxs import runtime as rt | ||
|
||
import pyblish.api | ||
|
||
from openpype.pipeline.publish import get_errored_instances_from_context | ||
|
||
|
||
class SelectInvalidAction(pyblish.api.Action): | ||
"""Select invalid objects in Blender when a publish plug-in failed.""" | ||
label = "Select Invalid" | ||
on = "failed" | ||
icon = "search" | ||
|
||
def process(self, context, plugin): | ||
errored_instances = get_errored_instances_from_context(context, | ||
plugin=plugin) | ||
|
||
# Get the invalid nodes for the plug-ins | ||
self.log.info("Finding invalid nodes...") | ||
invalid = list() | ||
for instance in errored_instances: | ||
invalid_nodes = plugin.get_invalid(instance) | ||
if invalid_nodes: | ||
if isinstance(invalid_nodes, (list, tuple)): | ||
invalid.extend(invalid_nodes) | ||
else: | ||
self.log.warning( | ||
"Failed plug-in doesn't have any selectable objects." | ||
) | ||
|
||
if not invalid: | ||
self.log.info("No invalid nodes found.") | ||
return | ||
invalid_names = [obj.name for obj in invalid if isinstance(obj, str)] | ||
if not invalid_names: | ||
invalid_names = [obj.name for obj, _ in invalid] | ||
invalid = [obj for obj, _ in invalid] | ||
self.log.info( | ||
"Selecting invalid objects: %s", ", ".join(invalid_names) | ||
) | ||
|
||
rt.Select(invalid) |
88 changes: 88 additions & 0 deletions
88
openpype/hosts/max/plugins/publish/validate_camera_attributes.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import pyblish.api | ||
from pymxs import runtime as rt | ||
|
||
from openpype.pipeline.publish import ( | ||
RepairAction, | ||
OptionalPyblishPluginMixin, | ||
PublishValidationError | ||
) | ||
from openpype.hosts.max.api.action import SelectInvalidAction | ||
|
||
|
||
class ValidateCameraAttributes(OptionalPyblishPluginMixin, | ||
pyblish.api.InstancePlugin): | ||
"""Validates Camera has no invalid attribute properties | ||
or values.(For 3dsMax Cameras only) | ||
""" | ||
|
||
order = pyblish.api.ValidatorOrder | ||
families = ['camera'] | ||
hosts = ['max'] | ||
label = 'Validate Camera Attributes' | ||
actions = [SelectInvalidAction, RepairAction] | ||
optional = True | ||
|
||
DEFAULTS = ["fov", "nearrange", "farrange", | ||
"nearclip", "farclip"] | ||
CAM_TYPE = ["Freecamera", "Targetcamera", | ||
"Physical"] | ||
|
||
@classmethod | ||
def get_invalid(cls, instance): | ||
invalid = [] | ||
if rt.units.DisplayType != rt.Name("Generic"): | ||
cls.log.warning( | ||
"Generic Type is not used as a scene unit\n\n" | ||
"sure you tweak the settings with your own values\n\n" | ||
"before validation.") | ||
cameras = instance.data["members"] | ||
project_settings = instance.context.data["project_settings"].get("max") | ||
cam_attr_settings = ( | ||
project_settings["publish"]["ValidateCameraAttributes"] | ||
) | ||
for camera in cameras: | ||
if str(rt.ClassOf(camera)) not in cls.CAM_TYPE: | ||
cls.log.debug( | ||
"Skipping camera created from external plugin..") | ||
continue | ||
for attr in cls.DEFAULTS: | ||
default_value = cam_attr_settings.get(attr) | ||
if default_value == float(0): | ||
cls.log.debug( | ||
f"the value of {attr} in setting set to" | ||
" zero. Skipping the check.") | ||
continue | ||
if round(rt.getProperty(camera, attr), 1) != default_value: | ||
cls.log.error( | ||
f"Invalid attribute value for {camera.name}:{attr} " | ||
f"(should be: {default_value}))") | ||
invalid.append(camera) | ||
|
||
return invalid | ||
|
||
def process(self, instance): | ||
if not self.is_active(instance.data): | ||
self.log.debug("Skipping Validate Camera Attributes.") | ||
return | ||
invalid = self.get_invalid(instance) | ||
|
||
if invalid: | ||
raise PublishValidationError( | ||
"Invalid camera attributes found. See log.") | ||
|
||
@classmethod | ||
def repair(cls, instance): | ||
invalid_cameras = cls.get_invalid(instance) | ||
project_settings = instance.context.data["project_settings"].get("max") | ||
cam_attr_settings = ( | ||
project_settings["publish"]["ValidateCameraAttributes"] | ||
) | ||
for camera in invalid_cameras: | ||
for attr in cls.DEFAULTS: | ||
expected_value = cam_attr_settings.get(attr) | ||
if expected_value == float(0): | ||
cls.log.debug( | ||
f"the value of {attr} in setting set to zero.") | ||
continue | ||
rt.setProperty(camera, attr, expected_value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "0.1.4" | ||
__version__ = "0.1.5" |